pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Bertheau <twanger@bluetwanger.de>
To: André Toscano <andre.toscano@uol.com.br>
Cc: pgsql-sql@postgresql.org
Subject: Re: Functions return a select in a table, which data type I
Date: Fri, 22 Oct 2004 15:38:29 +0200
Message-ID: <1098452309.2655.2.camel@dicaprio.akademie1.de> (raw)
In-Reply-To: <41A11FC4.4040909@uol.com.br>
References: <41A11FC4.4040909@uol.com.br>

В Пнд, 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@bluetwanger.de>




view thread (3+ messages)  latest in thread

Message-ID: <1098452309.2655.2.camel@dicaprio.akademie1.de>
Permalink:  ../1098452309.2655.2.camel@dicaprio.akademie1.de/
Also on:    postgresql.org/message-id/1098452309.2655.2.camel@dicaprio.akademie1.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: twanger@bluetwanger.de, andre.toscano@uol.com.br
  Subject: Re: Functions return a select in a table, which data type I
  In-Reply-To: <1098452309.2655.2.camel@dicaprio.akademie1.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox