Set-returning function returning a set-returning function?

Started by Philippe Langalmost 20 years ago1 messagesgeneral
Jump to latest
#1Philippe Lang
philippe.lang@attiksystem.ch

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