Reputation: 2015
mytable
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int(255) | NO | PRI | NULL | auto_increment |
| date | date | NO | | NULL | |
| answer_id | int(255) | NO | MUL | NULL | |
| count | int(255) | YES | | NULL | |
+-----------+----------+------+-----+---------+----------------+
SQL:
INSERT INTO mytable ('date', 'answer_id', 'count')
VALUES ('2013-12-05', '4', '1');
gives me ERROR 1064
Upvotes: 1
Views: 345
Reputation: 313
ERROR 1064 stands for syntax error.
Your column names should be wrapped with backtick on both side.
So change your SQL Query to:
INSERT INTO mytable ( `date` , `answer_id`, `count` )
VALUES ( '2013-12-05', 4 , 1 );
Upvotes: 1
Reputation: 155055
Error 1064 is a syntax error, in this case your column names shouldn't be in quotes (but they can be in backticks) and your integer values shouldn't be in quotes either.
Your statement should look like this:
INSERT INTO mytable ( `date` , `answer_id`, `count` )
VALUES ( '2013-12-05', 4 , 1 );
Upvotes: 3
Reputation: 254906
Columns shouldn't be enclosed in single quotes. Single quotes are used to delimit a string literal.
In your case you just omit any quotes around all columns.
If a column name matches a mysql keyword it needs to be wrapped with a backtick `
on either side.
Upvotes: 6