Re: BUG #1592: "with hold" cursor problem

From: Andrew - Supernews <andrew+nonews(at)supernews(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1592: "with hold" cursor problem
Date: 2005-04-11 15:10:12
Message-ID: slrnd5l4qk.2ilg.andrew+nonews@trinity.supernews.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2005-04-10, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Gabor Berenyi" <ber_(at)freemail(dot)hu> writes:
>> begin;
>> declare t cursor with hold for select function() as x from R;
>> commit;
>
>> Documentation says that the rows represented by a held cursor are copied
>> into a temporary file or memory area, but they are not, if they are results
>> of a function call. Instead, "commit" aborts the connection.
>
> Works for me. Could we see a complete, self-contained example?
> In particular I suppose that the details of function() might be
> relevant.

Someone mentioned this on IRC; I was going to post an analysis but I got
sidetracked with other stuff. The critical detail is that function()
has to be an SQL function declared stable (or possibly immutable, not
sure) and it must invoke a volatile function such as timeofday(). The
crash happens in CopySnapshot trying to copy a null snapshot.

Obviously the function definition is in itself illegal, so the workaround
is "don't do that", but the backend should probably do something more
useful than segfaulting.

Complete example:

test=# create function crashme() returns text as 'select timeofday()'
test-# language sql stable;
CREATE FUNCTION
test=# begin;
BEGIN
test=# declare t cursor with hold for select crashme() as x from pg_class;
DECLARE CURSOR
test=# commit;
server closed the connection unexpectedly

--
Andrew, Supernews
http://www.supernews.com - individual and corporate NNTP services

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Fuhr 2005-04-11 15:29:06 Re: BUG #1547: CREATE TYPE AS error
Previous Message Tom Lane 2005-04-11 14:54:43 Re: BUG #1547: CREATE TYPE AS error