Refcursor problem

Started by Dmitry Fomichevover 24 years ago3 messagesbugs
Jump to latest
#1Dmitry Fomichev
dfomichev@reldata.com

Hi,

I am running 7.2b3 and trying to make something like this work (new
refcursor stuff):

CREATE TABLE t (c text);

CREATE FUNCTION errtest(refcursor, text) RETURNS refcursor AS '
BEGIN
OPEN $1 FOR SELECT c FROM t WHERE c=$2;
RETURN $1;
END;
' LANGUAGE 'plpgsql';

INSERT INTO t VALUES ('123');

BEGIN;
SELECT errtest('rs', '123');
FETCH ALL IN rs;
COMMIT;

I am getting this error after FETCH ALL....

psql:errtest.sql:15: ERROR: MemoryContextAlloc: invalid request size
2139062147

If I tweak the function, the size in the error message (2139062147) stays
the same.
However, if I change the function to

CREATE FUNCTION errtest(refcursor, integer) RETURNS refcursor AS '
BEGIN
OPEN $1 FOR SELECT c FROM t WHERE c=text($2);
RETURN $1;
END;
' LANGUAGE 'plpgsql';

BEGIN;
SELECT errtest('rs', 123);
FETCH ALL IN rs;
COMMIT;

everything works fine. Am I missing something here? Workaround?
The OS is Linux Red Hat 7.1, kernel 2.4.5, glibc 2.2.4

Thanks for your help!

Dmitry Fomichev

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dmitry Fomichev (#1)
Re: Refcursor problem

Dmitry Fomichev <dfomichev@reldata.com> writes:

I am running 7.2b3 and trying to make something like this work (new
refcursor stuff):

CREATE TABLE t (c text);

CREATE FUNCTION errtest(refcursor, text) RETURNS refcursor AS '
BEGIN
OPEN $1 FOR SELECT c FROM t WHERE c=$2;
RETURN $1;
END;
' LANGUAGE 'plpgsql';

INSERT INTO t VALUES ('123');

BEGIN;
SELECT errtest('rs', '123');
FETCH ALL IN rs;
COMMIT;

I am getting this error after FETCH ALL....

psql:errtest.sql:15: ERROR: MemoryContextAlloc: invalid request size
2139062147

Nasty. It looks like SPI_cursor_open needs to be careful to copy
by-reference parameter values into the memory context created for
the cursor portal. Will fix.

regards, tom lane

#3Jan Wieck
JanWieck@Yahoo.com
In reply to: Tom Lane (#2)
Re: Refcursor problem

Tom Lane wrote:

Dmitry Fomichev <dfomichev@reldata.com> writes:

I am running 7.2b3 and trying to make something like this work (new
refcursor stuff):

CREATE TABLE t (c text);

CREATE FUNCTION errtest(refcursor, text) RETURNS refcursor AS '
BEGIN
OPEN $1 FOR SELECT c FROM t WHERE c=$2;
RETURN $1;
END;
' LANGUAGE 'plpgsql';

INSERT INTO t VALUES ('123');

BEGIN;
SELECT errtest('rs', '123');
FETCH ALL IN rs;
COMMIT;

I am getting this error after FETCH ALL....

psql:errtest.sql:15: ERROR: MemoryContextAlloc: invalid request size
2139062147

Nasty. It looks like SPI_cursor_open needs to be careful to copy
by-reference parameter values into the memory context created for
the cursor portal. Will fix.

It doesn't do? Blame it on me. Thanks.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com