Re: help using arrays in a function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: help using arrays in a function
Дата
Msg-id 11716.1077804462@sss.pgh.pa.us
обсуждение исходный текст
Ответ на help using arrays in a function  ("Jennifer Lee" <jlee@scri.sari.ac.uk>)
Список pgsql-general
"Jennifer Lee" <jlee@scri.sari.ac.uk> writes:
>                         WHILE a[i] LOOP

> I'm now testing our database on 7.4 and get an error with this function
> and I can't figure out how to fix it.
> ERROR:  invalid input syntax for type boolean: "100"
> CONTEXT:  PL/pgSQL function "array_element_compare" line 9 at while

plpgsql now enforces that the test expression of IF, WHILE, etc must be
a boolean.  The above is not.

This is pretty poor coding practice anyway, since even before 7.4 it
would have given wrong answers for arrays containing zeroes or arrays
whose lower index bound is not 1.  I'd suggest using the array_lower and
array_upper functions to determine the valid range of subscripts.
Something like

    FOR i IN array_lower(a,1) .. array_upper(a,1) LOOP

should work.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Randall Skelton
Дата:
Сообщение: Re: Simplyfying many equals in a join
Следующее
От: Karam Chand
Дата:
Сообщение: Index Information