From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Rikard Pavelic <rikard(dot)pavelic(at)zg(dot)htnet(dot)hr> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: problem selecting from function |
Date: | 2007-04-06 09:55:12 |
Message-ID: | 20070406095512.GA21873@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Apr 06, 2007 at 03:52:17AM +0200, Rikard Pavelic wrote:
> When I select from this function I get an error
>
> ERROR: record "red" has no field "id"
[...]
> create function select_ex1(out id int, out name1 varchar, out value1
> int) returns setof record as
> $$
> declare red record;
> begin
> for red in select id, name1, value1 from example1 LOOP
> id=red.id;
> name1=red.name1;
> value1=red.value1;
> return next;
The columns in the select list match the parameter names so you're
selecting the parameters, not the columns in example1. The query
is effectively:
for red in select NULL, NULL, NULL from example1 loop
The code should work if you qualify the columns:
for red in select e.id, e.name1, e.value1 from example1 e loop
--
Michael Fuhr
From | Date | Subject | |
---|---|---|---|
Next Message | Dominik Żyła | 2007-04-06 10:47:12 | Database replication. |
Previous Message | Martijn van Oosterhout | 2007-04-06 09:16:02 | Re: RES: Order by behaviour |