Re: [GENERAL] problems with dropped columns

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: [GENERAL] problems with dropped columns
Дата
Msg-id 3E66DD51.9060205@joeconway.com
обсуждение исходный текст
Ответ на Re: [GENERAL] problems with dropped columns  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Ответы Re: [GENERAL] problems with dropped columns  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Christopher Kings-Lynne wrote:
> I want to fix this bug, however I can't see how the example below is
> failing...  (Obeys dropped columns)  I'm not up with my SRFs, so would
> someone be able to post a concise SQL script that demonstrates the failure?
>
> I can see in the code that it should be failing, but I need a demonstrated
> example...

Taking it a bit further...

CREATE TABLE fk_test (f1 int, f2 int);
insert into fk_test(f1, f2) values(1, 21);
insert into fk_test(f1, f2) values(2, 22);

ALTER TABLE fk_test DROP COLUMN f2;
ALTER TABLE fk_test ADD COLUMN f3 int;

insert into fk_test(f1, f3) values(3, 33);
insert into fk_test(f1, f3) values(4, 34);

CREATE OR REPLACE FUNCTION test()
RETURNS SETOF fk_test AS '
   DECLARE
     rec fk_test%ROWTYPE;
   BEGIN
     FOR rec IN SELECT * FROM fk_test LOOP
       RETURN NEXT rec;
     END LOOP;
     RETURN;
   END;
' LANGUAGE 'plpgsql';

regression=# select * from test();
  f1 | f3
----+----
   1 |
   2 |
   3 |
   4 |
(4 rows)

regression=# ALTER TABLE fk_test DROP COLUMN f3;
ALTER TABLE
regression=# select * from test();
  f1
----
   1
   2
   3
   4
(4 rows)

regression=# ALTER TABLE fk_test ADD COLUMN f3 int;
ALTER TABLE
regression=# select * from test();
WARNING:  Error occurred while executing PL/pgSQL function test
WARNING:  line 5 at return next
ERROR:  Wrong record type supplied in RETURN NEXT

CREATE OR REPLACE FUNCTION test()
RETURNS SETOF fk_test AS '
   DECLARE
     rec fk_test%ROWTYPE;
   BEGIN
     FOR rec IN SELECT * FROM fk_test LOOP
       RETURN NEXT rec;
     END LOOP;
     RETURN;
   END;
' LANGUAGE 'plpgsql';

regression=# select * from test();
  f1 | f3
----+----
   1 |
   2 |
   3 |
   4 |
(4 rows)

Joe


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Rod Taylor
Дата:
Сообщение: Row level stats
Следующее
От: Alan Gutierrez
Дата:
Сообщение: Re: XML ouput for psql