Re: syntax question

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>, James Cooper <jim(at)luckydigital(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: syntax question
Date: 2003-02-24 15:17:40
Message-ID: 20030224151740.15417.qmail@web20805.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

--- Josh Berkus <josh(at)agliodbs(dot)com> wrote:
> you cannot select the results of
> a query directly into a
> RECORD variable without a loop.
>

Pardon??

kper=# create function test(integer) returns varchar
as 'declare stuff record; begin select * into stuff
from employee where empid =$1; return stuff.empnum;
end;' language 'plpgsql';
CREATE

kper=# select test(66664);
test
------
3094
(1 row)

kper=# select empid, empnum from employee where empid
= 66664;
empid | empnum
-------+--------
66664 | 3094
(1 row)

This functinality has been in pl/pgsql from early days
AFAIK. Be aware that this only works reliably if you
have some way to be sure of what will be selected
("empid" is a unique column in this example), because
the second and later rows to be returned from the
query will be silently discarded.

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-02-24 15:30:14 Re: syntax question
Previous Message Christoph Haller 2003-02-24 13:49:30 Re: Help with query involving aggregation and joining.