Problem with stored procedure and nested transactions

From: <p(dot)pierotti(at)mmbb(dot)it>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Problem with stored procedure and nested transactions
Date: 2018-10-30 14:03:05
Message-ID: 008501d47059$48073860$d815a920$@mmbb.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi everyone,

I have problems with stored procedures introduced in version 11.

I do not understand how to create a nested transaction, in this semplified
example:

create or replace procedure tst_prc(inout p_cod text) language plpgsql as
$procedure$

begin

p_cod := 'a';

begin

update aziende set mail = 'asd(at)asd(dot)asd' where id = 11; --1st
update

begin

update aziende set telefono = '0123456789' where id =
11; --2nd update

commit;

raise notice 'Inner';

end;

update aziende set telefono = '089' where id = 11; --3rd update

--commit;

rollback;

raise notice 'Outer';

end;

p_cod := 'b';

end;

$procedure$

The third update goes, rightly, in rollback; the problem is that the first 2
are committed.

I thought that the "BEGIN/END" block was used to create new transactions and
that each of them could be managed individually.

What am I doing wrong?

Best regards.

Paolo Pierotti

Viale Lombardia, 4 Lodi (LO)
M: +39 328 9035851

P: +39 075 8556435

W: <http://www.mmbb.it/> www.mmbb.it

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-10-30 14:05:57 Re: Problem with stored procedure and nested transactions
Previous Message Madan Kumar 2018-10-30 14:01:36 Re: How to change standby node to sync from the new master without rebooting the PostgreSQL service?