From: Marek Kilimajer <[EMAIL PROTECTED]>
        To: PHP <[EMAIL PROTECTED]>
        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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to