Reputation: 313
This is a pretty basic question, so apologies.
I have a simple SQL (MySQL5) table and I'm trying to command line insert data into it. But it keeps popping an error and I have no idea why.
This is my console output:
mysql> SHOW COLUMNS from queries;
+-------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| query | varchar(100) | NO | | NULL | |
| date | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| match | int(11) | YES | | NULL | |
+-------+-----------+------+-----+-------------------+-----------------------------+
4 rows in set (0.00 sec)
mysql> INSERT INTO queries (query, match) VALUES ('cheese', 4);
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 'match) VALUES ('cheese', 4)' at line 1
mysql>
What's going on? Why doesn't my INSERT INTO command work?
Upvotes: 0
Views: 225
Reputation: 5044
You need to have backtiks on match. match is a keyword in MySQL
INSERT INTO queries (`query`, `match`) VALUES ('cheese', 4);
Refer: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
Upvotes: 0
Reputation: 9323
match
is a keyword in MySQL. You have to escape it (and it's a good idea to do this anyway):
INSERT INTO queries (`query`, `match`) VALUES ('cheese', 4);
Upvotes: 3
Reputation: 146360
match
is a reserved MySQL word.
Try this instead (using backticks):
INSERT INTO queries (`query`, `match`) VALUES ('cheese', 4);
Upvotes: 7