我想在 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;
如何改进我的代码来执行它?谁能帮我?谢谢!
答案 0 :(得分:0)
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 $$: