beanquery icon indicating copy to clipboard operation
beanquery copied to clipboard

Support quoted identifiers

Open dnicolodi opened this issue 3 years ago • 4 comments
trafficstars

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?

dnicolodi avatar Oct 25 '22 14:10 dnicolodi

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

blais avatar Oct 26 '22 03:10 blais

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.

dnicolodi avatar Oct 26 '22 13:10 dnicolodi

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

blais avatar Oct 27 '22 02:10 blais

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

dnicolodi avatar Oct 27 '22 12:10 dnicolodi

Implemented in #153.

dnicolodi avatar Feb 03 '25 10:02 dnicolodi