views:

37

answers:

2

in sql server

begin tran
    select * from foos with (rowlock, xlock, holdlock) where id =7 
...
commit tran

will lock the row for reading and writing and it will hold the lock until the end of the transaction,

is there an equivalent of this in postgresql ?

A: 

Take a look at pg_advisory_lock()

Frank Heikens
+1  A: 

Try this:

BEGIN tran;
    SELECT * FROM foos FOR UPDATE;
...
COMMIT tran;

Reference: SELECT ... FOR UPDATE

Matthew Wood