Problem with the use of Array and Loop

From: "Benjamin RICHARD" <benjamin(at)intradot(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Problem with the use of Array and Loop
Date: 2003-04-18 08:16:11
Message-ID: 009001c30582$c5eb10b0$3c02a8c0@mourmansk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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}') ;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Gibbs 2003-04-18 08:29:51 Re: Date = current_timestamp inconsistency?
Previous Message Alessandro Bottoni 2003-04-18 07:43:53 Where I can find PL/pgSQL and Trigger Examples?