Re: Plpgsql function syntax error at first coalesce statement - Mailing list pgsql-general

From Tom Lane
Subject Re: Plpgsql function syntax error at first coalesce statement
Date
Msg-id 20959.1272238503@sss.pgh.pa.us
Whole thread Raw
In response to Re: Plpgsql function syntax error at first coalesce statement  (Jeff Ross <jross@wykids.org>)
List pgsql-general
Jeff Ross <jross@wykids.org> writes:
> On 04/25/10 14:20, Tom Lane wrote:
>> Uh, you're using that as the destination for the FOR loop's SELECT.
>> What exactly is the purpose of having a second SELECT within the loop?

> How else do I get the results I want--name, address, city, state, and so
> on through the list out to whatever calls this function?

Well, you could do

    SELECT all-that-stuff INTO some-record-variable FROM ...;
    RETURN NEXT some-record-variable;

which is more or less what the error message is suggesting.

Or you could merge the computations you want into the first SELECT
(the one in the FOR) and just RETURN NEXT directly from the FOR's
loop variable, instead of having two record variables.

Or you could eliminate the explicit loop altogether and just RETURN
QUERY one-big-query (if you're using a PG version new enough to have
RETURN QUERY).

            regards, tom lane

pgsql-general by date:

Previous
From: Jeff Ross
Date:
Subject: Re: Plpgsql function syntax error at first coalesce statement
Next
From: Megha
Date:
Subject: Help with pgpool-dbt2 database