Search Postgresql Archives

Re: Duplicate Unique Key constraint error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks alot for all your suggestions gentlemen.
I changed it to a SERIAL column and all the pain has been automatically alleviated :)

Thanks a ton.
~Harpreet

On 7/10/07, Tom Lane <tgl@xxxxxxxxxxxxx> wrote:
"Harpreet Dhaliwal" < harpreet.dhaliwal01@xxxxxxxxx> writes:
> Transaction 1 started, saw max(dig_id) = 30 and inserted new dig_id=31.
> Now the time when Transaction 2 started and read max(dig_id) it was still 30
> and by the time it tried to insert 31, 31 was already inserted by
> Transaction 1 and hence the unique key constraint error.

This is exactly why you're recommended to use sequences (ie serial
columns) for generating IDs.  Taking max()+1 does not work, unless
you're willing to lock the whole table and throw away vast amounts of
concurrency.

                        regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux