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 ?
Try this:
BEGIN tran;
SELECT * FROM foos FOR UPDATE;
...
COMMIT tran;
Reference: SELECT ... FOR UPDATE
Take a look at pg_advisory_lock()
精彩评论