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

Returning sets from functions?

From: mig(at)utdt(dot)edu
To: pgsql-sql(at)postgresql(dot)org
Subject: Returning sets from functions?
Date: 2000-04-23 14:15:20
Message-ID: 200004231415.LAA04384@ant.utdt (view raw or flat)
Thread:
Lists: pgsql-sql
Consider
    create function followers(text) returns setof text as 
          'select id from ids where id > $1 '
          language 'sql';

The function seems to work OK:
    select followers('h');
does return all indexes after the index 'h'.

On the other hand,
    select * from ids where id in (select followers('h'));
produces the message
  ERROR:  An operand to the '=' operator returns a set of text,
        but '=' takes single values, not sets.

Apparently the phrase
    select followers('h');
returns a set with members which are 'setof text'. psql has no trouble
displaying all rows, but the parser does ...

So, my question is: can I produce a set in a function so that it
mimicks perfectly the return set of a select query?

I am using PG 6.5.3; is this already solved in the 7.0 beta?

Thanks

Miguel Sofer


pgsql-sql by date

Next:From: Tom LaneDate: 2000-04-23 14:57:45
Subject: Re: TOAST (was: BLOB)
Previous:From: Peter EisentrautDate: 2000-04-23 13:48:26
Subject: Re: TOAST (was: BLOB)

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