https://www.sqlite.org/lang_corefunc.html
Function Simulation: REPEAT()
Not having any functions doesn’t mean that you can’t simulate them. You can. Take REPEAT(), for instance. Apart from the RANDOMBLOB(), you can also generate a ZEROBLOB(). It’s a blob with lots of zeros in it. But you can’t just go and do this:
-- Simulate REPEAT('abc', 3)
replace(zeroblob(3), 0, 'abc')
quote(zeroblob(3)) yields X'000000'
-- Simulate REPEAT('abc', 3)
replace(substr(quote(zeroblob(2)), 3, 3), '0', 'abc')
-- Or more generally: X = 'abc', Y = 3
replace(substr(quote(zeroblob((Y + 1) / 2)), 3, Y), '0', X)
https://stackoverflow.com/questions/11568496/how-to-simulate-repeat-in-sqlite
Function Simulation: LPAD() and RPAD()
REPEAT() was easy. But REPEAT() was inspired by LPAD() and RPAD(), which is similar to REPEAT(), except that a character is padded to the left or right of another string, until a given length of the resulting string is reached. ZEROBLOB() will help us again! Let’s consider RPAD():
-- Simulate RPAD('abc', 7, '-')
'abc' || replace(replace(substr(quote(zeroblob(4)), 3, 4), '''', ''), '0', '-')
-- Or more generally:
-- RPAD() Using X = 7, Y = '-', Z = 'abc'
Z || replace(
replace(
substr(
quote(zeroblob((X + 1) / 2)),
3, (X - length(Z))
), '''', ''
), '0', Y
)
-- LPAD() Using X = 7, Y = '-', Z = 'abc'
replace(
replace(
substr(
quote(zeroblob((X + 1) / 2)),
3, (X - length(Z))
), '''', ''
), '0', Y
) || Z