Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNgym-0004JR-N6 for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 18:37:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kNgyl-0001RE-Kz for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 18:37:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNgyl-0001Qo-DL for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 18:37:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNgyj-000062-BX for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 18:37:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 08UIbNjB891497; Wed, 30 Sep 2020 14:37:23 -0400 From: Tom Lane To: Matthias Apitz cc: pgsql-general@lists.postgresql.org Subject: Re: Problem close curser after rollback In-reply-to: <20200930171312.GA14156@r314251-amd64> References: <20200930171312.GA14156@r314251-amd64> Comments: In-reply-to Matthias Apitz message dated "Wed, 30 Sep 2020 19:13:12 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <891495.1601491043.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 30 Sep 2020 14:37:23 -0400 Message-ID: <891496.1601491043@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Matthias Apitz writes: > El d=C3=ADa mi=C3=A9rcoles, septiembre 30, 2020 a las 05:26:39p. m. +020= 0, Laurenz Albe escribi=C3=B3: >> On Wed, 2020-09-30 at 13:32 +0000, Wiltsch,Sigrid wrote: >>> What can I do so that the cursor is retained despite rollback? >> You cannot start a transaction while you are reading a cursor; you prob= ably >> get a warning "there is already a transaction in progress". > I think we will prepare the ten-liner in ESQL/C for further discussion. I don't think you really need to: the point seems clear enough. I don't especially like the idea you are suggesting though. The general principle in SQL is that a rolled-back transaction should have no effect after it's been rolled back. Allowing a cursor it creates to survive the rollback would fly in the face of that principle. Quite aside from that, there are technical issues. As a perhaps egregious case, what if the cursor's output depends on objects that will disappear in the rollback? begin; create type rainbow as enum ('red', 'green', 'blue'); create table r (f1 rainbow); insert into r values ('red'); declare c cursor with hold for select * from r; rollback; fetch all from c; Even if we surmount the implementation issues around holding onto the bits emitted by the cursor, the FETCH is going to fail to return data to the application, because it doesn't know how to interpret those bits anymore. So the short answer is you can't have that. Find another way to design your application. regards, tom lane