Re: function returning result set of varying column

Поиск
Список
Период
Сортировка
От Ivan Sergio Borgonovo
Тема Re: function returning result set of varying column
Дата
Msg-id 20080603152841.64719a02@dawn.webthatworks.it
обсуждение исходный текст
Ответ на Re: 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
On Tue, 3 Jun 2008 09:01:02 -0400
"maria s" <psmg01@gmail.com> wrote:

> Hi Friends,
> Thanks for all your for the reply.
> 
> I tried the function and when I execute it using
> select * from myfunction()
> it says
> ERROR:  a column definition list is required for functions
> returning "record"
> 
> Could you please help me to fix this error?
> 
> Thanks so much for your help.

you can specify the returned types in each statement that call your
function or you can specify the returned type in the function itself.

CREATE OR REPLACE FUNCTION myfunction(out col1 int, out col2
varchar(32), out ...)
RETURNS
SETOF
RECORD
AS
$body$
DECLARE rec record;
BEGIN FOR rec IN (   SELECT * FROM sometable) LOOP   col1:=rec.col1;   col2:=rec.col2;
--    col3:=...;   RETURN NEXT; END LOOP; RETURN;
END;
$body$

> > 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$

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



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

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