Thread: BUG #5117: Table type Function Bug when column dropped

BUG #5117: Table type Function Bug when column dropped

From
"cf of"
Date:
The following bug has been logged online:

Bug reference:      5117
Logged by:          cf of
Email address:      ccooffeee@hotmail.com
PostgreSQL version: 8.4 (maybe all)
Operating system:   Linux
Description:        Table type Function Bug when column dropped
Details:

create table test_table
   (
    key1 integer,
    key2 integer,
    key3 integer
   );

   CREATE OR REPLACE FUNCTION test_function()
     RETURNS SETOF test_table AS
   $BODY$
   DECLARE
    _Ret RECORD;
   BEGIN
    FOR _Ret IN
     Select * From test_table
    LOOP
     RETURN NEXT _Ret;
    END LOOP;
   END;
   $BODY$
     LANGUAGE 'plpgsql';

   insert into test_table values( 1, 1, 1 );
   insert into test_table values( 2, 2, 2 );
   insert into test_table values( 3, 3, 3 );
   insert into test_table values( 4, 4, 4 );

   alter table test_table drop column key3;

   select * from test_function();
   ERROR:  wrong record type supplied in RETURN NEXT
   DETAIL:  Number of returned columns (2) does not match expected column
count (3).
   CONTEXT:  PL/pgSQL function "test_function" line 7 at RETURN NEXT


Thx.

Re: BUG #5117: Table type Function Bug when column dropped

From
Alvaro Herrera
Date:
cf of wrote:

>    alter table test_table drop column key3;
>
>    select * from test_function();
>    ERROR:  wrong record type supplied in RETURN NEXT
>    DETAIL:  Number of returned columns (2) does not match expected column
> count (3).

Known problem, fixed in HEAD (8.5-to-be).  Not sure how backpatchable
the fix was.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support