0

There seem to be two kinds of parsers in the sqlite shell, one that interprets escape sequences only inside double quotes and only for dot-commands ("\n", e.g. for .separator), and one that doesn't, for everything else:

sq3> CREATE TABLE bhist (cmd varchar not null);
sq3> .mode csv
sq3> SELECT length('\n');
"length('\n')"
2
sq3> SELECT length("\n");
"length(""\n"")"
2
sq3> 
sq3> .separator '\t'
sq3> .import .bash_history bhist
Error: multi-character column separators not allowed for import
sq3> .separator "\t" "\n"
sq3> .import .bash_history bhist
sq3> SELECT count(*) from bhist;
count(*)
3404
sq3> 

Note how only the last .separator (double-quoted escape sequences in dot-command) seems to work. I can find no documentation on this. What gives?

usretc
  • 723
  • 4
  • 9
  • Backslashes are not escape characters in SQL string literals. See https://www.sqlite.org/lang_expr.html#literal_values_constants_ – Shawn Jun 30 '20 at 21:41
  • Yeah. See transcript above. That passage refers to SQL, not sqlite shell – usretc Jun 30 '20 at 21:46
  • This is why `SELECT length('\n');` returns 2. – Shawn Jun 30 '20 at 21:50
  • Read the transcript please, as related to .separator and .import. SQL is one thing, sqlite shell is another. – usretc Jun 30 '20 at 22:16
  • SQL is one thing, dot commands in the shell are another, with different syntax, yes. – Shawn Jul 01 '20 at 04:35
  • Yes, I knew all that. Thanks. So, where is the syntax for . separator "\t" (or "\n", or "\040" octal) documented? They all work. – usretc Jul 01 '20 at 08:13

0 Answers0