Problem with the use of Array and Loop - Mailing list pgsql-general

From Benjamin RICHARD
Subject Problem with the use of Array and Loop
Date
Msg-id 009001c30582$c5eb10b0$3c02a8c0@mourmansk
Whole thread Raw
Responses Re: Problem with the use of Array and Loop
List pgsql-general
Hi,
I would like to read each value of an array.
To do this i create the following function which return me a parse error
near '[' (in the Raise notice line)
What mistake did i do ?
And maybe there is a better way to do this in Postgre

CREATE FUNCTION array_int(_int4) RETURNS int4 AS 'DECLARE
    start_char INTEGER DEFAULT 4;
    len_char INTEGER;
    array_count INTEGER;
    val_tmp VARCHAR;
    tmp INTEGER;
BEGIN
SELECT INTO val_tmp array_dims( $1 ) ; --get the length of the array =>
[x:y]
SELECT INTO len_char ( position('']'' in val_tmp) - start_char ) ; --get the
length of y
SELECT INTO array_count substring(val_tmp from start_char for len_char)
; --get the value of y


FOR tmp IN 1..(array_count) LOOP
    RAISE NOTICE ''current value = %'' , $1[tmp] ;
END LOOP;

RETURN array_count ;

END;
-------------------------------------------------------------------
Try :
select array_int('{5,3,6,9,7,5,10,5,87,45,12,65,98,21,65,21}') ;


pgsql-general by date:

Previous
From: Alessandro Bottoni
Date:
Subject: Where I can find PL/pgSQL and Trigger Examples?
Next
From: "Peter Gibbs"
Date:
Subject: Re: Date = current_timestamp inconsistency?