Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are MySQL syntax error messages so bad?

MySQL syntax errors are often pretty vague, only specifying the line where the error occurs. Writing a parser that produces accurate and useful error message is not completely trivial, but it's not an open research problem: most compilers for general purpose programming languages produce errors messages that are much more useful.

So why doesn't MySQL's parser produce better error messages? Is it something to do with MySQL specifically, or the SQL grammar generally that makes this extremely difficult?

Here's an example:

SELECT * FROM foo WHERE bar > 0 AND baz NOT NULL ORDER BY qux ASC 

MySQL generates the following error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL ORDER BY qux ASC'

In fact, NOT NULL should be IS NOT NULL. So why doesn't MySQL generate an error like Unexpected token NOT at line 3 column 8?

like image 986
michiakig Avatar asked Mar 28 '14 15:03

michiakig


People also ask

What is SQL syntax error?

Overview. This SQL error generally means that somewhere in the query, there is invalid syntax. Some common examples: Using a database-specific SQL for the wrong database (eg BigQuery supports DATE_ADD, but Redshift supports DATEADD) Typo in the SQL (missing comma, misspelled word, etc)

What is 42000 error in MySQL?

The ERROR 1064 (42000) mainly occurs when the syntax isn't set correctly i.e. error in applying the backtick symbol or while creating a database without them can also create an error, if you will use hyphen in the name, for example, Demo-Table will result in ERROR 1064 (42000). Now database is created successfully.

How do I clear MySQL errors?

You can try "\! clear" , it will execute clear shell command. "\!" is used to execute shell command. in *nix it will clear your command prompt.


1 Answers

Oracle is where open source software goes to die. They have a disincentive to make the freely available competitor to their commercial database applications very good. It was good enough that no one would make another, for a while, and now I prefer MariaDB and the other forks when I am given a choice.

like image 199
Brian Stinar Avatar answered Sep 28 '22 22:09

Brian Stinar