Re: Plpgsql function syntax error at first coalesce statement

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Ross <jross(at)wykids(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Plpgsql function syntax error at first coalesce statement
Date: 2010-04-25 23:35:03
Message-ID: 20959.1272238503@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Ross <jross(at)wykids(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hiroshi Inoue 2010-04-26 00:19:49 Re: [GENERAL] trouble with to_char('L')
Previous Message Megha 2010-04-25 22:25:48 Help with pgpool-dbt2 database