0

Hello

Sometimes I get a duplicate key which I want to ignore or discard.

This is a example and has nothing to do with the actual query. I simple want to state columns/values

insert into table(Time_Stamp,Time_Stamp_ms,p1) values (time,timems,'1')

Where the first two are my PK.

I see that

insert into table(Time_Stamp,Time_Stamp_ms,p1) values (time,timems,'1') on duplicate key

exists but it asks me for a UPDATE. How do I update on "Time_Stamp" and "Time_Stamp_ms"?

Im sorry for not explaining correctly my problem.

2
Contributors
2
Replies
9
Views
3 Years
Discussion Span
Last Post by riahc3
0

Where the first two are my PK.

No need to update the PK's if they're the same:

insert IGNORE into table(Time_Stamp, Time_Stamp_ms, p1) values (time, timems, '1')

The above has as drawback that ALL errors are ignored.

or:

insert into table(Time_Stamp,Time_Stamp_ms,p1) values (time,timems,'1') on duplicate key update p1 = '1'

Edited by pritaeas

0

I figured it out:

insert into table(Time_Stamp,Time_Stamp_ms,p1,p2) values (time,timems,'1','2') on duplicate key update p1 = '1',p2='2'

That works for me. Did not know you could update more than one.

Edited by riahc3

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.