beancount / beanquery

A customizable light-weight SQL query tool that works on tabular data, including Beancount.
GNU General Public License v2.0
20 stars 12 forks source link

Support quoted identifiers #114

Open dnicolodi opened 1 year ago

dnicolodi commented 1 year ago

Currently BQL uses single ' and double " quotes interchangeably as string delimiters and does not have the concept of quoted identifiers. This make is impossible to have column names that collide with BQL keywords or that contain non-alphanumeric characters. This is sometimes annoying.

Standard SQL uses single quotes ' for string literals and double quotes " for quoting identifiers. https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Should BQL do the same? It would be a tiny patch to the parser. However, I expect this to break a fair number of user queries.

@blais, do you have an opinion?

blais commented 1 year ago

I think you looked into this deeper than I did and I agree with you!

dnicolodi commented 1 year ago

I was looking for an opinion on weather supporting the feature is worth breaking backward compatibility.

Considering that BQL queries stored in Beancount input files are extremely likely to be using ' as string delimiter because " is the Beancount string delimiter, I think the backward compatibility problem may not be so severe, but this is still a quite important syntax change.

blais commented 1 year ago

I forget if I added escapes in the Beancount syntax. That's going to be crucial for this change.

dnicolodi commented 1 year ago

Yes, the parser supports escaping double quotes as \". For v3 we could also consider having Python-like triple quotes.