[英]How to execute two transactions concurrently in Postgresql?
我想在Postgresql中同時執行兩個事務,這就是我得到的
--The first transaction should modify the age of Paul
BEGIN;
DECLARE newage INTEGER;
--the original age of Paul is 32
newage := Select age FROM COMPANY WHERE name = Paul;
newage := newage+10;
update company set age := Sage where name = Paul;
commit;
--The second Transaction shows all information about Paul including his age
Begin
select * from company where name = 'Paul';
commit;
這兩部分均在同一SQL編輯器中編寫。 我的第一個問題是它無法編譯,我收到消息
ERROR: syntax error at or near "INTEGER"
LINE 2: DECLARE newage INTEGER;
如何改善我的代碼以執行它? 誰能幫我? 謝謝!
pl/pgsql
聲明變量 newage
因此,結果查詢如下所示:
DO $$ DECLARE
newage INTEGER;
BEGIN
SELECT age INTO newage FROM companey WHERE name = 'Paul';
newage := newage+10;
UPDATE company SET age = newage where name = 'Paul';
END $$:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.