On all versions starting from 8.0 where subtransactions were introduced,
this causes an assertion failure:
postgres=# BEGIN;
BEGIN
postgres=# DECLARE foocur CURSOR FOR SELECT a FROM
generate_series(1,500000) a;
DECLARE CURSOR
postgres=# SAVEPOINT sp;
SAVEPOINT
postgres=# FETCH foocur;
a
âââ
1
(1 row)
postgres=# error; -- cause subxact abort
ERROR: syntax error at or near "error"
LINE 1: error;
^
postgres=# ROLLBACK TO SAVEPOINT sp;
ROLLBACK
postgres=# FETCH ALL FROM foocur;
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.
In server log:
TRAP: FailedAssertion("!(((file) > 0 && (file) < (int) SizeVfdCache &&
VfdCache[file].fileName != ((void *)0)))", File: "fd.c", Line: 1101)
When the first row is fetched from the cursor, the function scan is
materialized in a temporaray file. At the error, the temporary file is
deleted. But the FETCH ALL command expects the cursor to be still open,
and the file to exist, so it fails.
If assertions are disabled, you get an "ERROR: unexpected end of tape"
error instead.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com