plpgsql: type of array cells

From: Amit Dor-Shifer <amit(dot)dor(dot)shifer(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: plpgsql: type of array cells
Date: 2011-10-06 00:07:59
Message-ID: CAAznTxHWNi_mY8+3c5d04M2bYa_THARzRnZkPoV3yub1z1pFgA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm trying to use an array of objects in plpgsql (postgresql 8.4):

drop type if exists test_t cascade;

create type test_t AS
(
i integer,
s text
);

create or replace function test2()
RETURNS SETOF test_t AS
$$
DECLARE
arr test_t ARRAY[3];
tmp test_t;
BEGIN
FOR i in 1 .. 3
LOOP
-- ok. Can write to test_t.i
tmp.i:=i;
-- ok. Can assign a cell from arr to a test_t object
arr[i]:=tmp;
-- error:
arr[i].i=3;
RETURN NEXT tmp;
END LOOP;
END;
$$
LANGUAGE plpgsql;

I'm getting an error when attempting to interpret this function:

NOTICE: drop cascades to function test2()
ERROR: syntax error at or near "."
LINE 21: arr[i].i=3;
^

********** Error **********

ERROR: syntax error at or near "."
SQL state: 42601
Character: 272

Isn't arr[i] of type test_t??

Thanks,
Amit

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2011-10-06 00:15:34 Re: Problem with pg_upgrade 9.0 -> 9.1
Previous Message David Johnston 2011-10-05 23:58:34 Re: Selecting All Columns Associated With Maximum Value of One Column