Problem with the use of Array and Loop

Поиск
Список
Период
Сортировка
От Benjamin RICHARD
Тема Problem with the use of Array and Loop
Дата
Msg-id 009001c30582$c5eb10b0$3c02a8c0@mourmansk
обсуждение исходный текст
Ответы Re: Problem with the use of Array and Loop  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Alessandro Bottoni
Дата:
Сообщение: Where I can find PL/pgSQL and Trigger Examples?
Следующее
От: "Peter Gibbs"
Дата:
Сообщение: Re: Date = current_timestamp inconsistency?