From: | "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Set-returning function returning a set-returning function? |
Date: | 2006-06-09 10:55:30 |
Message-ID: | 6C0CF58A187DA5479245E0830AF84F421D0DBD@poweredge.attiksystem.ch |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
( Yes, I re-read the title 5 times, it sounds correct to me! :) )
I've got a SRF similar to:
-----------------------------------
CREATE FUNCTION srf_perl
(
IN i_a int4,
INOUT io_b int4,
OUT o_c int4
)
RETURNS SETOF record
AS
$$
@i = ('i_a');
@io = ('io_b');
@o = ('o_c');
$c = 0;
foreach $i (@i) {$input{$i} = @_[$c++]};
foreach $io (@io) {$input{$io} = @_[$c]; $output{$io} = @_[$c++]};
foreach $o (@o) {$output{$o} = @_[$c++]};
$output{'io_b'} = $input{'i_a'} * 2;
$output{'o_c'} = $input{'io_b'} * 3;
return_next \%output;
$output{'io_b'} = $input{'i_a'} * 22;
$output{'o_c'} = $input{'io_b'} * 33;
return_next \%output;
$output{'io_b'} = $input{'i_a'} * 222;
$output{'o_c'} = $input{'io_b'} * 333;
return_next \%output;
return undef;
$$
LANGUAGE 'plperl' VOLATILE;
----------------------------------
I can call it with "select * from srf_perl(1, 2)", that's fine.
Now I'd like to call srf_perl from another SRF function, which would return the same data. I've tried different things, with no success. The last thing I tried was:
----------------------------------
CREATE OR REPLACE FUNCTION srf_plpgsql()
RETURNS SETOF record
AS
$$
DECLARE
rec RECORD;
BEGIN
for rec in select * from srf_perl(1,2) loop
return next rec;
end loop;
return;
END;
$$
LANGUAGE 'plpgsql' VOLATILE;
----------------------------------
I always get the following error: ERROR: a column definition list is required for functions returning "record"
Any idea how I can acheive this? Note that what I'm showing here is just an illustration. I agree the second function is a nonsense...
Thanks!
----------------------------------
Philippe Lang, Ing. Dipl. EPFL
Attik System
rte de la Fonderie 2
1700 Fribourg
Switzerland
http://www.attiksystem.ch
Tel: +41 (26) 422 13 75
Fax: +41 (26) 422 13 76
From | Date | Subject | |
---|---|---|---|
Next Message | Agent M | 2006-06-09 11:09:12 | Re: Fabian Pascal and RDBMS deficiencies in fully implementing the relational model |
Previous Message | Terry Lee Tucker | 2006-06-09 10:45:13 | Re: OID |