Re: can a function return a virtual table?

From: Kai Hessing <kai(dot)hessing(at)hobsons(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: can a function return a virtual table?
Date: 2005-04-20 07:23:24
Message-ID: 3cmebiF6n5ocpU1@individual.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

and thanks for the answer ;) (*upps* just noticed, that I sent the
answer accidently direct to poster^^ *sorry*)

Michael Fuhr schrieb:

>> I'll pick a nit and point out that the above isn't a valid query:
>>
>> test=> SELECT xyz, abc FROM (SELECT * FROM tablex WHERE status > -1);
>> ERROR: subquery in FROM must have an alias
>> HINT: For example, FROM (SELECT ...) [AS] foo.

*yeah* sure you're right. I shortened it to much^^

>> In this simple example you could omit the subquery altogether:
>> SELECT xyz, abc FROM tablex WHERE status > -1;

It is not about such a simple example. When joining tables (especially
with outer joins) it isn't trivial ;)

>> See the documentation for writing set-returning functions (SRFs).
>> The following links should get you started (if you're using a version
>> of PostgreSQL older than 8.0, then see the documentation for that
>> version):

Thanks, I think this is what I've searched for (btw. we use 7.3). But
what I want to do is:

CREATE FUNCTION active(char) RETURNS setof $1 AS '
SELECT * FROM $1 WHERE status>-1;
' LANGUAGE SQL;

But this does not work. So I'll use views instead ;) It also should be
more performant. Thanks...

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ramakrishnan Muralidharan 2005-04-20 10:21:25 Re: 'Select INTO" in Execute (dynamic query )
Previous Message Ramakrishnan Muralidharan 2005-04-20 04:39:24 Re: Debet-Credit-Balance Calculation