how can I returns a set of integer in a plpgsql function? - Mailing list pgsql-general

From Yi Zhao
Subject how can I returns a set of integer in a plpgsql function?
Date
Msg-id 1232005077.3109.9.camel@localhost.localdomain
Whole thread Raw
In response to Autovacuum daemon terminated by signal 11  ("Justin Pasher" <justinp@newmediagateway.com>)
List pgsql-general
hi, all:
there is a function in postgresql contrib "int_arrgreagte":

CREATE OR REPLACE FUNCTION int_array_enum(int4[])
RETURNS setof integer
AS '$libdir/int_aggregate','int_enum'
LANGUAGE C IMMUTABLE STRICT;

I can use this function like this:
chry=# SELECT int_array_enum('{1,2}');
or
chry=# SELECT * from int_array_enum('{1,2}');
result:
int_array_enum
----------------
              1
              2

also, I can use it like this:
SELECT int_array_enum('{1,2}'), int_array_enum('{1,3}');
result:
 int_array_enum | int_array_enum
----------------+----------------
              1 |              1
              2 |              3


I try to write my own function with the same return type in plpgsql:
create or replace function my_int_array_enum(state integer[]) returns
setof integer as $$
declare
     i integer;
begin
for i in array_lower(state,1)..array_upper(state,1) loop
return next state[i];
end loop;
return;
end;
$$ language 'plpgsql' immutable;

but, when I use my function like this: test=# SELECT
my_int_array_enum('{1,2}');
I got the error said as below:
ERROR:  set-valued function called in context that cannot accept a set
(I know, SELECT * from my_int_array_enum('{1,2}') is ok)

can anybody tell me the reason, thanks for any help:D

regards,


pgsql-general by date:

Previous
From: "m zyzy"
Date:
Subject: one-click installer postgresql-8.3.5-1-linux.bin failed
Next
From: "Scott Marlowe"
Date:
Subject: Re: one-click installer postgresql-8.3.5-1-linux.bin failed