Search Postgresql Archives

Re: Duplicate Unique Key constraint error

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

 




On Jul 10, 2007, at 13:22 , Harpreet Dhaliwal wrote:

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.

I thought this would be taken care by the database itself by locking the transactions but now I really don't know how does this locking takes place
in postgres.

Why would the server lock the table? It can't know your intention is to add one to the number returned and insert. If this is what you want, you have to lock the table explicitly.

Please guide me throug to get rid of this problem.

This exact reason is why sequences are often used for primary keys. I recommend you change your primary key.


Michael Glaesemann
grzm seespotcode net




[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