Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old October 9th, 2003, 06:48 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Insert with subquery doesn't return error


Hi All,

I'm writing a row to a table using:

"INSERT INTO volunteerevents
SELECT volunteer.id, event.id, 0, null
FROM volunteer, event
WHERE volunteer.userid = "{$user}"
AND event.location = "{$location}"
AND event.dateofevent = "{$dateofevent}"";

There is a primary key on the volunteerevents table (volunteerid, eventid).

If this query is run twice with the same values I would expect an 'Error 1062' duplicate key error. However, that's not the case, the query returns no error but does show via mysql_affected_rows() ==0 that it didn't insert a second row. I've written code to detect the 1062 error and send the user a message.

If I execute basically the same query but no subselect:

"INSERT INTO volunteerevents
VALUES (1,1,0,NULL)";

I do receive the expected error 1062.

Is this a MySQL bug? Feature?

Is there a workaround or should I first check the table to see if the row exists? Which I would rather not do since the database access costs a bit.



Reply With Quote
  #2  
Old October 14th, 2003, 10:38 AM
Marklarius Marklarius is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ramat-Gan, Central, Israel
Posts: 1 Marklarius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Marklarius Send a message via AIM to Marklarius
RE: Insert with subquery doesn't return error

"Prior to MySQL 4.0.1, INSERT ... SELECT implicitly operates in IGNORE mode. As of MySQL 4.0.1, you should specify IGNORE explicitly to ignore records that would cause duplicate-key violations."

http://www.mysql.com/doc/en/INSERT_SELECT.html

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Insert with subquery doesn't return error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway