pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: p.pierotti@mmbb.it
To: pgsql-general@postgresql.org
Subject: Problem with stored procedure and nested transactions
Date: Tue, 30 Oct 2018 15:03:05 +0100
Message-ID: <008501d47059$48073860$d815a920$@mmbb.it> (raw)

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@asd.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 

 

Attachments:

image003.png (image/png, 4.9K) download view image

view thread (3+ messages)  latest in thread

Message-ID: <008501d47059$48073860$d815a920$@mmbb.it>
Permalink:  ../008501d47059$48073860$d815a920$@mmbb.it/
Also on:    postgresql.org/message-id/008501d47059$48073860$d815a920$@mmbb.it

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: p.pierotti@mmbb.it
  Subject: Re: Problem with stored procedure and nested transactions
  In-Reply-To: <008501d47059$48073860$d815a920$@mmbb.it>
  References: <008501d47059$48073860$d815a920$@mmbb.it>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox