Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only quote non-syntactic names and reserved words in dbQuoteIdentifier #427

Open
hadley opened this issue May 26, 2022 · 5 comments
Open

Comments

@hadley
Copy link
Member

hadley commented May 26, 2022

Using https://www.sqlite.org/c3ref/keyword_check.html to capture all reserved words.

This isn't very important, but it does help dbplyr generate more natural SQL.

@hadley hadley changed the title Only quote non-syntactic names and reserved words Only quote non-syntactic names and reserved words in dbQuoteIdentifier May 26, 2022
@krlmlr
Copy link
Member

krlmlr commented May 27, 2022

Interesting. Should we experiment with an sqliteQuoteIdentifier()?

@hadley
Copy link
Member Author

hadley commented May 27, 2022

Why wouldn't this just be a method of dbQuoteIdentifier()?

@krlmlr
Copy link
Member

krlmlr commented May 27, 2022

dbplyr will have to special-case anyway, a separate new experimental entry point is easier to deprecate/change later on.

IIUC, sqlite3_keyword_check() only checks if a string is a keyword, not if it is syntactic. The only reliable reference seems to be the tokenizer, https://github.com/mackyle/sqlite/blob/master/src/tokenize.c (with character classes defined elsewhere). The rules don't seem to be that complex, though.

@krlmlr
Copy link
Member

krlmlr commented May 27, 2022

The other thing to consider -- if we aim to build SQL that is "pretty enough" to be used permanently and remain unchanged for years, what happens if SQLite introduces a keyword later on? If it's only for aesthetic purposes, I agree it's useful.

Should we do this for duckdb too?

@hadley
Copy link
Member Author

hadley commented May 27, 2022

I think adding reserved words would be pretty rare, as it would potentially break lots of existing SQL.

For duckdb, see duckdb/duckdb#3718

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants