[英]How to execute two transactions concurrently in Postgresql?
I want to execute concurrently two transactions in Postgresql and that's what I've got 我想在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;
Both parts were written in the same SQL Editor. 这两部分均在同一SQL编辑器中编写。 My first problem is that it doesn't compile, I obtain the message
我的第一个问题是它无法编译,我收到消息
ERROR: syntax error at or near "INTEGER"
LINE 2: DECLARE newage INTEGER;
How can I improve my code to execute it? 如何改善我的代码以执行它? Can anyone help me?
谁能帮我? Thanks!
谢谢!
pl/pgsql
pl/pgsql
声明变量 newage
newage
So the result query looks like: 因此,结果查询如下所示:
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.