The MySQL SQL Error 1064 Blues

 

       Writing error messages is an art. Sadly, most of us lack talent in that area. One of the prime examples that you see with SQL User Interfaces is the MySQL SQL Error 1064.

SQL Error [1064] [42000]: 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 'select @var' at line 2

Error position: line: 1

Explicit and clear, it ain't.  I am using DBeaver for this example, but the issue can be reproduced on MySQL Workbench, Toad, and many other tools.  In the following, an environment variable is set on the first line, and then a SELECT is used to return that variable. However, we receive a response of 1064. 




So what happened?  While both lines were input to the console, only the second line was executed. When we ask the server about @var, it has no knowledge of it and replies with the 1064 Error.

"But we typed it in!" Yeah, we typed it in, but the set was not executed by the server. You must ensure that both the SET and the SELECT are executed to obtain the desired results.

Another response is that a NULL value is returned by the query.  

One of the more challenging aspects of learning to use SQL is navigating the learning curve, particularly in interpreting error messages. And 1064 will become familair.

Comments

Popular posts from this blog

Does Artificial Intelligence Query MySQL Better Than You?

Tracking MySQL Query Plans Over Time Part One

Database Administration Query Repository