Skip site navigation (1) Skip section navigation (2)

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

From: Markus Bertheau <twanger(at)bluetwanger(dot)de>
To: André Toscano <andre(dot)toscano(at)uol(dot)com(dot)br>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Functions return a select in a table, which data type I
Date: 2004-10-22 13:38:29
Message-ID: 1098452309.2655.2.camel@dicaprio.akademie1.de (view raw or flat)
Thread:
Lists: 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_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;
';

-- 
Markus Bertheau <twanger(at)bluetwanger(dot)de>


In response to

Responses

pgsql-sql by date

Next:From: Davide NegriDate: 2004-10-22 13:52:36
Subject: Log
Previous:From: JNDate: 2004-10-22 12:04:18
Subject: now() + integer, not rounded to whole day

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group