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}') ;