Re: Functions return a select in a table, which data type I - Mailing list pgsql-sql

From Markus Bertheau
Subject Re: Functions return a select in a table, which data type I
Date
Msg-id 1098452309.2655.2.camel@dicaprio.akademie1.de
Whole thread Raw
In response to Functions return a select in a table, which data type I must use? (Brazilian User)  (André Toscano <andre.toscano@uol.com.br>)
Responses Re: Functions return a select in a table, which data type I
List pgsql-sql
В Пнд, 22.11.2004, в 00:07, André Toscano пишет:
> Hello, friends.
>
> If anybody can help, how can I do a FUNCTION return a result from a
> SELECT in a table in PostgreSQL?
> My Problem is the RETURN TYPE from a FUNCTION, I don´t know what I have
> to use to return the data as a select result.
>
> Example:
> ----------------
>
> DROP FUNCTION ACADEMICO.teste(int4);
>
> CREATE FUNCTION ACADEMICO.teste(int4)
> RETURNS ?????
> AS
> '
>     select cod_aluno, nome, cpf from ACADEMICO.TB_alunos
>
> '
> LANGUAGE 'SQL';

CREATE TYPE foo_type AS (cod_aluno TEXT, nome TEXT, cpf TEXT);
CREATE FUNCTION bar(int4)RETURNS SETOF foo_typeLANGUAGE 'SQL'AS '
DECLAREvar_rec foo_type;
BEGINFOR var_rec IN SELECT cod_aluno, nome, cpf FROM table WHERE ...     LOOP    RETURN NEXT var_rec;END LOOP;RETURN;
END;
';

--
Markus Bertheau <twanger@bluetwanger.de>



pgsql-sql by date:

Previous
From: Christoph Haller
Date:
Subject: Re: Finding duplicated values
Next
From: Larry Lennhoff
Date:
Subject: Create interval using column value?