elliotchance / vsql

✌️ Single-file or PostgreSQL-server compatible transactional SQL database written in pure V.
https://vsql.readthedocs.io
MIT License
299 stars 20 forks source link

'name' is reserved: cant use 'name' as a column name #103

Closed BEN00262 closed 2 years ago

BEN00262 commented 2 years ago

Hi was trying to create a table with 'name' as a column but got a crash, looking into the lexer i realized that name is marked as a keyword. Is this by design?

vsql> create table person (name character varying(100));
# cli execution error: vsql.SQLState42601: syntax error: near "NAME"
elliotchance commented 2 years ago

The SQL standard defines:

<key word> ::=
    <reserved word>
  | <non-reserved word>

NAME falls in the list of non-reserved words. As far as I can tell, the standard doesn't have a rule saying an <identifier> cannot be a <non-reserved word> but this will cause problems with the parser if NAME needs to be a keyword in the future. So as a precautionary measure I register all key words in the parser as off limits.

I realize it's kind of annoying for many common words, but it seems like the safer option to just disallow them all now. You can use "name".

elliotchance commented 2 years ago

That being said, I think the error message should be clearer with a suggestion so it's not so bizarre:

syntax error: near "NAME" (using key word as identifier?)

elliotchance commented 2 years ago

@BEN00262 Turns out you can use non reserved words as identifiers: https://github.com/elliotchance/vsql/releases/tag/v0.24.1