Re: Functions return a select in a table, which data type I

Re: Functions return a select in a table, which data type I

am 22.10.2004 15:38:29 von twanger

В Пнд, 22.11.2004, в 00:07, André Toscano =D0=
¿Ð¸ÑˆÐµÑ=82:
> Hello, friends.
>=20
> If anybody can help, how can I do a FUNCTION return a result from a=20
> SELECT in a table in PostgreSQL?
> My Problem is the RETURN TYPE from a FUNCTION, I don´t know what I h=
ave=20
> to use to return the data as a select result.
>=20
> Example:
> ----------------
>=20
> DROP FUNCTION ACADEMICO.teste(int4);
>=20
> CREATE FUNCTION ACADEMICO.teste(int4)
> RETURNS ?????
> AS
> '
> select cod_aluno, nome, cpf from ACADEMICO.TB_alunos
>=20
> '
> LANGUAGE 'SQL';

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

--=20
Markus Bertheau


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly