开发者

equivalent of rowlock xlock holdlock (sql server) for postgres

开发者 https://www.devze.com 2023-01-17 19:39 出处:网络
in sql server begin tran select * from foos with (rowlock,开发者_运维问答 xlock, holdlock) where id =7

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()

0

精彩评论

暂无评论...
验证码 换一张
取 消