codeschool / sqlite-parser

JavaScript implentation of SQLite 3 query parser
MIT License
331 stars 57 forks source link

Why are invalid statements parsed without errors? #46

Closed pplanner16 closed 6 years ago

pplanner16 commented 7 years ago

Hello, If I execute the following in the sqlite3 CLI -

sqlite> select 1,2 union select 3,4,5;

I receive an error, as expected -

Error: SELECTs to the left and right of UNION do not have the same number of result columns

why does sqlite-parser not recognize it as invalid?

nwronski commented 7 years ago

That statement is valid, syntactically, but not valid semantically. sqlite-parser parser does not have these kinds of semantic validations in its current form.

If you want to check statements for these types of issues, you need a linting/validation tool that accepts the ASTs generated by this parser. Many semantic validations would also require knowledge of the database schema for the statements (e.g., wrong column data type).