Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHUs8-0004dl-Vt for pgsql-general@arkaria.postgresql.org; Tue, 30 Oct 2018 14:19:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gHUs7-0005HO-75 for pgsql-general@arkaria.postgresql.org; Tue, 30 Oct 2018 14:19:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHUs6-0005HH-OA for pgsql-general@lists.postgresql.org; Tue, 30 Oct 2018 14:19:54 +0000 Received: from smtpcmd12131.aruba.it ([62.149.156.131]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gHUs3-0001LO-1z for pgsql-general@postgresql.org; Tue, 30 Oct 2018 14:19:53 +0000 Received: from LAPDOGPP ([79.8.85.37]) by smtpcmd12.ad.aruba.it with bizsmtp id tqKo1y00B0oKgTz01qKoH6; Tue, 30 Oct 2018 15:19:49 +0100 From: To: "'Adrian Klaver'" , References: <008501d47059$48073860$d815a920$@mmbb.it> <26082fd6-fd38-b6cb-b77b-24620a91a7d3@aklaver.com> In-Reply-To: <26082fd6-fd38-b6cb-b77b-24620a91a7d3@aklaver.com> Subject: R: Problem with stored procedure and nested transactions Date: Tue, 30 Oct 2018 15:19:47 +0100 Message-ID: <009301d4705b$9d429bb0$d7c7d310$@mmbb.it> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Content-Language: it Thread-Index: AQGnArJ9HnpK48kikcjuYj17ijuCewJFbCplpYCFtxA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aruba.it; s=a1; t=1540909189; bh=vdrSkyUkJ/NdOHLz/mINnH6vPS3TN9U8jm4wpOxgsTI=; h=From:To:Subject:Date:MIME-Version:Content-Type; b=XbeGtYtZzGkwHgzURlA8U9ztlIpERJo0YkNxbrgXregAF2Jipo4i0+aDD9xmQHTOZ rIdjVqJLunrG2GqFopeInClCHzkh/qjzQAfSxs0iP673+pXGzaMLmzJqjmpoDS8huH fN96ZqqcPqGqFFbtB8vQi0X9hmya7LDxXE8KX9Wx4LqRsWlOfkGrBmvQq5s+z7Fdze Nhb6V0Dq+dVpCkzx16Kv/5rsf7ZMCJrMr/SQ7Jqyq6DZavOxd0jqe0KlhUNR0drQGd Ww4KHFsb9QvGVhcIoZeLPgzM3YnYZMm3TvNxzv5vEqsslqxJKpDwz8rKpmUOXfSNYy RgblgroKuoi3Q== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thanks, I had already read it. What I cannot find is how to get the behavior I described, is there a = way? Paolo Pierotti=20 =20 Viale Lombardia, 4 Lodi (LO)=20 M: +39 328 9035851=20 P: +39 075 8556435 W:=A0www.mmbb.it=20 -----Messaggio originale----- Da: Adrian Klaver =20 Inviato: marted=EC 30 ottobre 2018 15:06 A: p.pierotti@mmbb.it; pgsql-general@postgresql.org Oggetto: Re: Problem with stored procedure and nested transactions On 10/30/18 7:03 AM, p.pierotti@mmbb.it wrote: > Hi everyone, >=20 > I have problems with stored procedures introduced in version 11. >=20 > I do not understand how to create a nested transaction, in this=20 > semplified example: >=20 > *create**or**replace**procedure*tst_prc(*inout*p_cod *text*)=20 > *language*plpgsql *as**$procedure$* >=20 > *begin* >=20 > p_cod :=3D 'a'; >=20 > *begin* >=20 > *update*aziende *set*mail =3D 'asd@asd.asd'*where*id =3D 11; --1st = update >=20 > *begin* >=20 > *update*aziende *set*telefono =3D '0123456789'*where*id =3D 11; --2nd=20 > update >=20 > *commit*; >=20 > *raise**notice*'Inner'; >=20 > *end*; >=20 > *update*aziende *set*telefono =3D '089'*where*id =3D 11; --3rd update >=20 > --commit; >=20 > *rollback*; >=20 > *raise**notice*'Outer'; >=20 > *end*; >=20 > p_cod :=3D 'b'; >=20 > *end*; >=20 > *$procedure$* >=20 > The third update goes, rightly, in rollback; the problem is that the=20 > first 2 are committed. >=20 > I thought that the =93BEGIN/END=94 block was used to create new=20 > transactions and that each of them could be managed individually. https://www.postgresql.org/docs/10/static/plpgsql-structure.html "It is important not to confuse the use of BEGIN/END for grouping = statements in PL/pgSQL with the similarly-named SQL commands for transaction = control. PL/pgSQL's BEGIN/END are only for grouping; they do not start or end a transaction. See Section 43.8 for information on managing transactions = in PL/pgSQL. Also, a block containing an EXCEPTION clause effectively forms = a subtransaction that can be rolled back without affecting the outer transaction. For more about that see " >=20 > What am I doing wrong? >=20 > Best regards. >=20 > ** >=20 > *Paolo Pierotti * >=20 > ** >=20 >=20 > http://www.mmbb.it/wp-content/uploads/2018/02/MMBB-logo.png >=20 > Viale Lombardia, 4 Lodi (LO) > M: +39 328 9035851 >=20 > P: +39 075 8556435 >=20 > W: www.mmbb.it >=20 -- Adrian Klaver adrian.klaver@aklaver.com