returning a resultset from a function

From: Anton Andreev <fn30762(at)fmi(dot)uni-sofia(dot)bg>
To: pgsql-general(at)postgresql(dot)org
Subject: returning a resultset from a function
Date: 2008-02-15 20:56:53
Message-ID: 47B5FC95.4020002@fmi.uni-sofia.bg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

How do I return a result set? Is there a better way in 'plpgsql' than
the one described below?
I do not want to make a select from a function(which pretty useful in
many cases):
SELECT * FROM getfoo();
, but I want to just call the function with SELECT getfoo();

--DROP FUNCTION getfoo();
--DROP type compfoo;

CREATE TYPE compfoo AS (f1 integer,f2 integer);

CREATE OR REPLACE FUNCTION getfoo() RETURNS SETOF compfoo
AS
$BODY$
declare
ret_row record;
BEGIN

FOR ret_row IN SELECT id,mun_id FROM mytable LOOP

RETURN next ret_row;

END LOOP;

RETURN;
END;
$BODY$
LANGUAGE 'plpgsql';

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Colin Wetherbee 2008-02-15 21:06:58 Re: PostgreSQL 8.3 on Debian, Ubuntu
Previous Message Tony Caduto 2008-02-15 20:49:26 Re: Pains in upgrading to 8.3