Re: functions in WHERE clause - Mailing list pgsql-sql

From Tom Lane
Subject Re: functions in WHERE clause
Date
Msg-id 10317.1141582600@sss.pgh.pa.us
Whole thread Raw
In response to Re: functions in WHERE clause  (sramsay@uga.edu)
Responses Re: functions in WHERE clause
List pgsql-sql
sramsay@uga.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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: functions in WHERE clause
Next
From: Jeff Frost
Date:
Subject: Re: Check/unique constraint question