On 18.02.2018 00:36, Richard Hipp wrote:

The current behavior of the printf() function in SQLite, goofy though
it may be, exactly mirrors the behavior of the printf() C function in
the standard library in this regard.

SQLite3 is not C. SQLite3 text storage is always Unicode. Thus SQL text
processing functions should work on Unicode. The current implementation
of the SQLite3 SQL printf() can not reliably be used for string padding.
And there is no simple alternative, AFAICS.

PostgreSQL returns 4 in all cases:

   length(format ('%4s', 'abc')),
   length(format ('%4s', 'äöü')),
   length(format ('%-4s', 'abc')),
   length(format ('%-4s', 'äöü'))

MySQL has lpad() and rpad() to achieve the same and also returns 4 in
all cases:

   length(lpad ('abc', 4, ' ')),
   length(lpad ('äöü', 4, ' ')),
   length(rpad ('abc', 4, ' ')),
   length(rpad ('äöü', 4, ' '))

I strongly believe that SQLite3 should follow suit.

sqlite-users mailing list

Reply via email to