pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Matthias Apitz <guru@unixarea.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Problem close curser after rollback
Date: Wed, 30 Sep 2020 14:37:23 -0400
Message-ID: <891496.1601491043@sss.pgh.pa.us> (raw)
In-Reply-To: <20200930171312.GA14156@r314251-amd64>
References: <DS7PR06MB6885FE41D39C4A2779CF13A7FF330@DS7PR06MB6885.namprd06.prod.outlook.com>
	<DM6PR06MB6169D90391183C6AA56376C4EA330@DM6PR06MB6169.namprd06.prod.outlook.com>
	<DS7PR06MB68850E9EB5C735140A5CC5D3FF330@DS7PR06MB6885.namprd06.prod.outlook.com>
	<f2af04c4fc6af1791c52b8bd2937522832b4df8c.camel@cybertec.at>
	<20200930171312.GA14156@r314251-amd64>

Matthias Apitz <guru@unixarea.de> writes:
> El día miércoles, septiembre 30, 2020 a las 05:26:39p. m. +0200, Laurenz Albe escribió:
>> 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 probably
>> 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





view thread (8+ messages)  latest in thread

Message-ID: <891496.1601491043@sss.pgh.pa.us>
Permalink:  ../891496.1601491043@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/891496.1601491043@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, guru@unixarea.de
  Subject: Re: Problem close curser after rollback
  In-Reply-To: <891496.1601491043@sss.pgh.pa.us>
  References: <DS7PR06MB6885FE41D39C4A2779CF13A7FF330@DS7PR06MB6885.namprd06.prod.outlook.com> <DM6PR06MB6169D90391183C6AA56376C4EA330@DM6PR06MB6169.namprd06.prod.outlook.com> <DS7PR06MB68850E9EB5C735140A5CC5D3FF330@DS7PR06MB6885.namprd06.prod.outlook.com> <f2af04c4fc6af1791c52b8bd2937522832b4df8c.camel@cybertec.at> <20200930171312.GA14156@r314251-amd64> <891496.1601491043@sss.pgh.pa.us>

* 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