Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help/guidance with ON DUPLICATE KEY error?

8 views
Skip to first unread message

BobMCT

unread,
Apr 5, 2013, 3:14:34 PM4/5/13
to
As stated in a previous post here, I'm trying to convert some older
queries to some newer syntax. I'm now beating my head on a stubborn
1064 error (invalid Syntax) on the following statement. The stated
shown is taken directly from the logs so its what is being
seen/processed by MySQL.

Here is that statement with actual field names and data values in
place:

INSERT INTO history
(_stcd, _gameid, _ddte, _stat, _dow, _wn, _soz, _pom)
VALUES ('AZ', '22', '130401', ' ', '1', '00170023', '3', '6')
ON DUPLICATE KEY UPDATE history SET
(_dow = '1', _wn = '00170023', _soz = '3', _pom = '6')

The mysqli_query function fails with a 1064 error. My eyes cannot
seem to identify what might be incorrect in my statement. I'm not
saying its generated absolutely correctly, just asking if anyone can
"see" my syntactical error?

Oh, and here are the table fields for reference:
Server version: 5.5.30-MariaDB
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| _stcd | char(2) | NO | PRI | NULL | |
| _gameid | char(3) | NO | PRI | NULL | |
| _ddte | char(6) | NO | PRI | NULL | |
| _stat | char(1) | YES | | | |
| _dow | char(1) | NO | | NULL | |
| _wn | varchar(60) | YES | | | |
| _soz | smallint(6) | YES | | 0 | |
| _pom | char(1) | NO | | NULL | |
+---------+-------------+------+-----+---------+-------+
8 rows in set (0.01 sec)

Salvatore

unread,
Apr 5, 2013, 4:03:48 PM4/5/13
to
On 2013-04-05, BobMCT <r.mar...@fdcx.net> wrote:
> Here is that statement with actual field names and data values in
> place:
>
> INSERT INTO history
> (_stcd, _gameid, _ddte, _stat, _dow, _wn, _soz, _pom)
> VALUES ('AZ', '22', '130401', ' ', '1', '00170023', '3', '6')
> ON DUPLICATE KEY UPDATE history SET
> (_dow = '1', _wn = '00170023', _soz = '3', _pom = '6')

The correct syntax is:

INSERT INTO table (fields) VALUES (values)
ON DUPLICATE KEY UPDATE col = value, ...

http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++

BobMCT

unread,
Apr 5, 2013, 7:13:38 PM4/5/13
to
On Fri, 5 Apr 2013 20:03:48 +0000 (UTC), Salvatore
<s...@yojimbo.hack.invalid> wrote:

>On 2013-04-05, BobMCT <r.mar...@fdcx.net> wrote:
>> Here is that statement with actual field names and data values in
>> place:
>>
>> INSERT INTO history
>> (_stcd, _gameid, _ddte, _stat, _dow, _wn, _soz, _pom)
>> VALUES ('AZ', '22', '130401', ' ', '1', '00170023', '3', '6')
>> ON DUPLICATE KEY UPDATE history SET
>> (_dow = '1', _wn = '00170023', _soz = '3', _pom = '6')
>
>The correct syntax is:
>
>INSERT INTO table (fields) VALUES (values)
>ON DUPLICATE KEY UPDATE col = value, ...
>
>http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

Thank you Salvatore. Removed the words "history SET" and it worked as
expected. And I was using the same reference page you specified, too.
0 new messages