On Wed, Dec 28, 2005 at 02:19:51AM -0600, Chris Thielen wrote: > James Keating wrote: > > >Well the simplest fix is the one that I did not implement in the first > >place, using "ON DUPLICATE KEY". However, I did not implement that > >because of its only being in version 4.1 of MySQL and I still use > >Debian stable for most production machines, which runs 4.0.x. > > > >Anyway, I will poke at it some more. > > > Read on for a portable fix called optimistic locking. > > > Pseudocode follows. I assume you are doing something like this:
You assume wrong. :) The code is doing UPDATE ... SET field = field + 1 ... which is almost always a much better idea than doing the increment in code. The race condition is in checking to see if the row already exists, and then using that information to decide if you should do an insert or an update. The example at the very bottom of http://lnk.nu/postgresql.org/5sl.html is how you would do this in a function in PostgreSQL, though there's no reason I can think of why you couldn't do that in perl instead (though it would perform much slower). -- Jim C. Nasby, Database Architect [EMAIL PROTECTED] Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?"