Re: functions in WHERE clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sramsay(at)uga(dot)edu
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: functions in WHERE clause
Date: 2006-03-05 18:16:40
Message-ID: 10317.1141582600@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

sramsay(at)uga(dot)edu writes:
> You can't do this:

> CREATE FUNCTION xpath(lquery) RETURNS ltree AS $$
> SELECT ltree FROM event WHERE ltree ~ $1;
> $$ LANGUAGE SQL;

That would work fine if you said RETURNS SETOF ltree.

> But I also can't get this kind of thing to work:

> CREATE FUNCTION xpath(lquery) RETURNS SETOF ltree AS $$
> DECLARE
> tree record;
> BEGIN
> FOR tree IN SELECT ltree FROM event WHERE ltree ~ $1 LOOP
> RETURN NEXT tree;
> END LOOP;
> RETURN;
> END
> $$ LANGUAGE plpgsql;

That should work too, except that you are trying to return a record
not an ltree value. Try "RETURN NEXT tree.ltree".

> Because SETOF won't work in a WHERE context.

Possibly you need to read the error messages you are getting more
closely, because I'm pretty sure whatever it said had nothing to
do with either SETOF or WHERE ...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff Frost 2006-03-05 18:32:59 Re: Check/unique constraint question
Previous Message Tom Lane 2006-03-05 17:59:51 Re: functions in WHERE clause