Allow using double-quotes for escaping.
codekitchen opened this issue · comments
I have a csv file that has a column named key
, which seems to be a reserved word in octosql? select key from myfile.csv
errors with
Error: couldn't parse query: invalid argument syntax error at position 11 near 'key'
I tried escaping the identifier with double-quotes following the SQL standard, but that seems to actually create a string literal in octosql, same as with single-quotes?
❯ octosql 'select "key" from myfile.csv limit 3'
+-------+
| col_0 |
+-------+
| 'key' |
| 'key' |
| 'key' |
+-------+
I also tried brackets (select [key] from
) but that errors as well. Is there a way to escape identifiers that I am missing in the docs? Thanks!
Hey @codekitchen!
You can escape keywords (and also complex file paths) using backticks. So in this case that would be:
SELECT `key` FROM myfile.csv
However, keep in mind that if you're using bash, you need to escape backticks, so the above becomes:
octosql 'SELECT \`key\` FROM myfile.csv'
That said, using double quotes for escaping is a good idea (following the SQL standard, as you said). Thanks for it! It would also partially solve #295.
I'll update the issue title to track adding this (changing from the current behaviour of treating double-quotes as string literals).
aha, thank you. and 👍 on allowing double-quotes as is standard.
one note: escaping the backticks isn't necessary in bash (and zsh) if you wrap the whole query in single-quotes, e.g. this works fine:
octosql 'select `key` from myfile.csv'
but if wrapping in double-quotes, you do need to escape the backticks:
octosql "select \`key\` from myfile.csv"
@codekitchen FYI double quotes for literals have been released as part of v0.12.0.