PRINTF - newlines, tabs etc?
(1) By midijohnny on 2021-11-18 21:22:22 [link] [source]
From the docs I understand that SQLite has its own implementation of 'printf', rather than matching the C implementation. - so it can provide some more specific formatting options.
But is there something fundamental about the way this is written that precludes the use of escaped characters for TAB "\t" , newline "\n" etc? (maybe platform independence issues with this?)
I found a workaround, so not a huge problem - but just more wordy and less standard:
SELECT PRINTF("x%cx",char(9)) -- works, just not the same in C (etc) INTERSECT SELECT PRINTF("x\tx") -- no rows: "\t" is returned literally rather than outputting a TAB.
The printf() function does not interpret backslash-escape sequences in either C or SQLite. That is something that happens during translation, by a C or C++ compiler, from string literals in the source text to char sequences in the compiled output. And since SQLite does not implement the non-SQL convention of backslash escaping in its string literals, your examples would not work even if quoted correctly.
In SQL, the doublequote is used to delimit identifiers, not string literals. In SQL, a string literal is delimited by singlequote characters, except where they are paired within the quoted text.
(3) By midijohnny on 2021-11-22 14:08:25 in reply to 2 [link] [source]
Thank you for the clarification and explanation. So: I will use the following format going forward (single quotes, not double).