Bug in PL/pgSQL FOR cursor variant

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: PostgreSQL Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Bug in PL/pgSQL FOR cursor variant
Date: 2010-06-21 08:05:43
Message-ID: 4C1F1D57.9060802@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

postgres=# CREATE FUNCTION func() RETURNS VOID AS $$
declare
cur CURSOR IS SELECT generate_series(1,10) AS a;
BEGIN
FOR erec IN cur LOOP
raise notice 'row %', erec.a ;
IF (erec.a = 5) THEN CLOSE cur; END IF;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# SELECT func();
NOTICE: row 1
NOTICE: row 2
NOTICE: row 3
NOTICE: row 4
NOTICE: row 5
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

Reproducible on 8.4 and CVS HEAD, the "FOR cursor" statement didn't
exist on earlier versions.

The problem is that exec_stmt_forc keeps using a pointer to the Portal,
which becomes invalid if the cursor is closed in the middle. Patch
attached, will apply..

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

Attachment Content-Type Size
plpgsql-forc-fix-1.patch text/x-diff 3.1 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tatsuhito Kasahara 2010-06-21 10:02:03 make_greater_string() does not return a string in some cases
Previous Message S. Brett Sutton 2010-06-21 00:34:58 Re: BUG #5511: Handling of case in Username and database names are inconsistant.