How to emulate REPEAT() in SQLite

A simplified version of @Lukas Eder's solution using hex() instead of quote:

-- X = string
-- Y = number of repetitions

replace(hex(zeroblob(Y)), '00', X) 

If its a single character you want to repeat, you can use printf function.

Bellow is an example where x is repeated 10 times. The key is the * in the format string which specifies that the width of the field will be passed as a parameter:

sqlite> select printf('%.*c', 10, 'x');
xxxxxxxxxx

To repeat multiple characters you can then replace() each x by the longer string, much as in Lukas's answer above.


A solution was inspired by this answer to a related question, here:

How to emulate LPAD/RPAD with SQLite

I wanted to share this on Stack Overflow, as this may be useful to other SQLite users. The solution goes like this:

-- X = string
-- Y = number of repetitions

replace(substr(quote(zeroblob((Y + 1) / 2)), 3, Y), '0', X)