Re: function returning result set of varying column

Поиск
Список
Период
Сортировка
От Bart Degryse
Тема Re: function returning result set of varying column
Дата
Msg-id 48450995.A3DD.0030.0@indicator.be
обсуждение исходный текст
Ответ на function returning result set of varying column  ("maria s" <psmg01@gmail.com>)
Ответы Re: function returning result set of varying column  ("maria s" <psmg01@gmail.com>)
Список pgsql-sql
Hi Maria,
Try something like
CREATE OR REPLACE FUNCTION myfunction() RETURNS SETOF RECORD AS
$body$
DECLARE
  rec record;
BEGIN
  FOR rec IN (
    SELECT * FROM sometable)
  LOOP
    RETURN NEXT rec;
  END LOOP;
  RETURN;
END;
$body$
LANGUAGE 'plpgsql' VOLATILE;
 
As you can see, the number and type of the output fields only depends on whatever table you query in the FOR loop.
It's not magic though. It just postpones defining the number and type of the output fields until querying the function.
You will have to define the output fields when querying your function, like
select * from myfunction() as ("field1" integer, "field2" text, ...)

>>> "maria s" <psmg01@gmail.com> 2008-06-02 22:40 >>>
Hi friends,
I am very new to plsql.

I have to write a function that quries few tables and  returns a resultset of varying column.

 In that case I cannot predefine the table with column.
If I use RETURNS SETOF then I should know the number of columns and its type?!

Is there anyway to return a resultset with any number of column?

Thanks for your help.

-maria

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

Предыдущее
От: "maria s"
Дата:
Сообщение: function returning result set of varying column
Следующее
От: "maria s"
Дата:
Сообщение: Re: function returning result set of varying column