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