Re: syntax question - Mailing list pgsql-sql

From Jeff Eckermann
Subject Re: syntax question
Date
Msg-id 20030224151740.15417.qmail@web20805.mail.yahoo.com
Whole thread Raw
In response to Re: syntax question  (Josh Berkus <josh@agliodbs.com>)
Responses Re: syntax question
List pgsql-sql
--- Josh Berkus <josh@agliodbs.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/


pgsql-sql by date:

Previous
From: Christoph Haller
Date:
Subject: Re: Help with query involving aggregation and joining.
Next
From: Tom Lane
Date:
Subject: Re: syntax question