Thread: Array in stored procedure

Array in stored procedure

From
Michal Hlavac
Date:
DECLARE
   groups integer[];
   tmp RECORD;
   tmpi integer;
BEGIN
   FOR tmp IN SELECT i_group_id FROM l_group_to_user WHERE i_user_id =
$1 LOOP
     SELECT i_group_id INTO tmpi FROM s_group WHERE i_group_id =
tmp.i_group_id;
     groups[] := tmpi;
     RETURN NEXT tmp.i_group_id;
   END LOOP;
   RETURN NULL;
END

hello,

I am using v7.3.5. I cannot fill and use array "groups". It is possible
in stored procedures???
Row: groups[] := tmpi;
returns error: syntax error at or near "["
thanx... miso

Re: Array in stored procedure

From
Tom Lane
Date:
Michal Hlavac <hlavki@medium13.sk> writes:
>      groups[] := tmpi;
> returns error: syntax error at or near "["

This is supported in PG 7.4 (although you do need to provide a subscript
expression ...)

            regards, tom lane