Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does --- and ---- mean in mysql?

I know -- means starting of comment in mysql. But what does --- and ---- mean?? See my console log.

mysql> --
mysql> ---
    -> 
    -> ;
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 '-' at line 1
mysql> ----
    -> 
    -> ;
Query OK, 0 rows affected (0.00 sec)
  • First one seems a comment.
  • Second one is NOT
  • Third one is not too. They are expecting something.

I wrote an sql file that contains header comments started with --- characters. Due to this next query does not run. It throws error. Like this.

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 '-' at line 1

like image 606
Shiplu Mokaddim Avatar asked Dec 25 '12 15:12

Shiplu Mokaddim


2 Answers

There needs to be whitespace or a control character after the second dash. From the MySQL manual:

MySQL Server supports three comment styles:

  • From a # character to the end of the line.

  • From a -- sequence to the end of the line. In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on). This syntax differs slightly from standard SQL comment syntax, as discussed in Section 1.8.5.5, “-- as the Start of a Comment”.

  • From a /* sequence to the following */ sequence, as in the C programming language. This syntax enables a comment to extend over multiple lines because the beginning and closing sequences need not be on the same line.

(Emphasis mine.) And, as usual, this only applies to MySQL. :P

like image 137
Ry- Avatar answered Oct 21 '22 00:10

Ry-


This nothing but syntax check error,

Other than '--', mysql considering everything as sql statement. Since
'---' is not a valid statement it's showing error.
that means there should be at least one space after '--' then only it will be considered as valid comment.

Hope this helps you,

like image 2
Mari Avatar answered Oct 21 '22 00:10

Mari