MySQL Parser Error Reporting

The error reporting for the MySQL query parser can be pretty brutal. For example:

create table books
(
  id int not null auto_increment,
  author_id int not null,
  title varchar(255)
  price decimal(10,2),
  constraint fk_books_author foreign key (author_id) references authors(id),    
  primary_key (id)
);  


The table definition above generates this error:

ERROR 1064 (42000) at line 1: 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 'price decimal(10,2),
constraint fk_books_author foreign key (author_id) refer' at line 6


Any idea where the problem is? The "line 1" bit is extremely misleading. It turns out the problem is that the the table definition uses "primary_key" instead of "primary key".
Design Element
MySQL Parser Error Reporting
Posted Oct 11, 2005 — 4 comments below




 

Werner — Oct 12, 05 428

There is a comma missing after "title varchar(255)"???

Scott Stevenson — Oct 12, 05 429 Scotty the Leopard

Actually, that's true too, but the main attraction was the primary_key bit. The point is that it says "line 1," which is less than helpful. :)

Jesper — Oct 12, 05 430

Doesn't "line 1" in these contexts mean "line 1, where by line 1 we mean that it's the statement that started on line 1, and the next line is line 2, even if it's physically line 32 when counting line breaks and stuff like that"?

Scott Stevenson — Oct 12, 05 432 Scotty the Leopard

The message is technically correct, it's just not very readable.




 

Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.





Copyright © Scott Stevenson 2004-2015