Hi,
I prefer to update and if the number of updated rows equals 0 do an insert. So in case of update I need only one roundtrip. If insert is far more common in this case it might be better try insert and catch the error. But I try to avoid running on an error intentionally.
When logging to a compact table that stores data in an aggregate form, I used something like that:
BEGIN; UPDATE ... ;
if (!affected_rows) { INSERT ... ;
if (error) { ROLLBACK; UPDATE ... ; } }
COMMIT;
I added the error check with a second UPDATE try after INSERT to increase accuracy. In fact, INSERTs were sometimes failing because of concurrency, and this was the only viable solution I found to avoid losing data.
Best regards -- Matteo Beccati http://phpadsnew.com/ http://phppgads.com/
---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly