Reputation: 303
I am having problems inserting into a timestamp field.
Here is my schema:
CREATE TABLE `sponsorlog` (
`updated` timestamp,
`user` varchar(200) NOT NULL,
`company` varchar(200) NOT NULL,
`change` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Here is the insert command:
insert into sponsorlog (user, company, change, updated)
values ('[email protected]', '3M', 'Sponsor Jon Bove added', '2015-08-10 17:43:32');
And the error is the typical useless MySQL error. It seems to be pointing at the date/time value but I can't see anything wrong with it. Any ideas?
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 'change, updated) values ('[email protected]', '3M', 'Sponsor Jon Bove added',' at line 1
Upvotes: 0
Views: 42
Reputation: 44881
change
is a reserved word and needs to be quoted. In MySQL the identifier quote character is the backtick: `
insert into sponsorlog (user, company, `change`, updated)
values ('[email protected]', '3M', 'Sponsor Jon Bove added', '2015-08-10 17:43:32');
Also user
is a non-reserved keyword, so to be consistent you might want to use quotes for all columns.
If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it
Upvotes: 2