patch fixing the old RETURN NEXT bug

From: "Sergey E(dot) Koposov" <math(at)sai(dot)msu(dot)ru>
To: pgsql-patches(at)postgresql(dot)org
Subject: patch fixing the old RETURN NEXT bug
Date: 2006-02-12 17:15:53
Message-ID: Pine.LNX.4.44.0602121958090.15708-200000@lnfm1.sai.msu.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Hello All,

I'm proposing the fix of this bug:
http://archives.postgresql.org/pgsql-hackers/2005-02/msg00498.php

The exact SQL code exposing the error:

----------

create table usno (ra real, dec real, bmag real, rmag real,ipix int8);
CREATE OR REPLACE FUNCTION xxx(refcursor) RETURNS refcursor AS '
DECLARE query varchar;
BEGIN
query = ''SELECT * FROM usno'';
OPEN $1 FOR EXECUTE query;
RETURN $1;
END;
' LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION yyy() RETURNS SETOF usno AS '
DECLARE rec record;
DECLARE cur refcursor;
BEGIN
cur=xxx(''curs_name'');
LOOP
FETCH cur into rec;
EXIT WHEN NOT FOUND;
RETURN NEXT rec;
END LOOP;
RETURN;
END;
' LANGUAGE plpgsql;

insert into usno values(1,2,3,4);
select * from yyy();
alter table usno add column errbox box;
select * from yyy();
alter table usno drop column errbox;
select * from yyy();

-------

The problem with that is in fact in pl_exec.c in function
compatible_tupdesc(), which do not check for the deleted attributes.

The patch is attached.

Regards,
Sergey

*****************************************************
Sergey E. Koposov
Max Planck Institute for Astronomy
Web: http://lnfm1.sai.msu.ru/~math
E-mail: math(at)sai(dot)msu(dot)ru

Attachment Content-Type Size
pl_exec.diff text/plain 1.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-02-12 17:28:43 Re: patch fixing the old RETURN NEXT bug
Previous Message Jim Buttafuoco 2006-02-12 16:41:57 Re: Analyze and vacuum, they are sort of mandatory....

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2006-02-12 17:28:43 Re: patch fixing the old RETURN NEXT bug
Previous Message Simon Riggs 2006-02-12 16:38:46 Re: Scrollable cursors and Sort performance