Re: function to return query result

From: Ashley Clark <aclark(at)ghoti(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: function to return query result
Date: 2000-11-29 14:43:35
Message-ID: 20001129084334.A22781@ghoti.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

* Peter Maas in "[GENERAL] function to return query result" dated
* 2000/11/29 12:34 wrote:

> Hi,

Hi,

> I tried to write a PL/PGSQL function that returns a query result:

I don't think you can do that yet, but let's look at what you've got.

> CREATE FUNCTION pms() RETURNS pmsummen AS '
> declare
> result pmsummen;
> BEGIN
> select into result * from pmsummen;
> return result;
> END;
> ' LANGUAGE 'plpgsql';

Yeah, the return value of a function can't be a recordset.

> I tried lots of variations of this function (employing PERFORM,
> replacing pmsummen by record, ...) but everything failed. My first
> intention was to write a parameterized view but this doesn't seem to
> exist in PostgresQL so I tried to write a function returning a query
> result. Thanks for your help.

Why don't you use a view? Something like:

create view test as select a.a, a.b, a.c, b.a, b.b
from a, b
where a.id=b.id;

Then you can do selects on the view using a where clause:

select *
from test
where a.a='somevalue';

--
ashley clark

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Phil Steinke 2000-11-29 14:45:21 plpgsql variable trouble
Previous Message Gordan Bobic 2000-11-29 13:36:06 Re: insertion times ..