Re: help using arrays in a function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jennifer Lee" <jlee(at)scri(dot)sari(dot)ac(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: help using arrays in a function
Date: 2004-02-26 14:07:42
Message-ID: 11716.1077804462@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Jennifer Lee" <jlee(at)scri(dot)sari(dot)ac(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-02-26 14:16:03 Re: ORDER BY different locales
Previous Message Karel Zak 2004-02-26 13:35:33 ORDER BY different locales