Search Postgresql Archives

blocking INSERTs

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

 



I want to do the following:

BEGIN;
SELECT ... FROM table WHERE a = 1 FOR UPDATE;
UPDATE table SET ... WHERE a = 1;
if that resturns zero then
INSERT INTO table (...) VALUES (...);
END;

The problem is that I need to avoid race conditions. Sometimes I get primary key exceptions on the INSERT.

I think I need to lock the table in share mode to keep inserts from happening, but that blocks vacuums, and blocked vacuums block other things behind them. So how do I get around this?

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to majordomo@xxxxxxxxxxxxxx)

[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