Re: Auto-increment value

From: Date: Wed, 18 Sep 2002 13:30:28 +0000
Subject: Re: Auto-increment value
Groups: php.general 
Request: Send a blank email to php-general+get-116740@lists.php.net to get a copy of this message
From: Marek Kilimajer <kilimajer@webglobe.sk> To: PHP <php-general@lists.php.net> Subject: Re: [PHP] Auto-increment value You encounter a race condition bob parker wrote: >SELECT idno ORDER BY idno DESC LIMIT 1; >assuming idno is what gets auto incremented >bob To avoid the race it is necessary to do the whole thing in a transaction, for postgresql this works BEGIN; INSERT ... whatever SELECT ... the last idno END; The last idno is available to the user inside the transaction. I beleive the terminating ';' are not needed in php generated sql statements but they don't hurt either. bob

« previous php.general (#116740) next »