Thread: Trouble with ARRAYs

Trouble with ARRAYs

From
Ralph Smith
Date:
There seems to be inadequate info on filling arrays from a table, (vs keyboarding), and
how to do a lookup in an array.  I've tried to almost no avail.

- - - - - - -
I have a loop that I'm executing thousands of times and inside of it I have

        SELECT INTO  myvar   column1  FROM mytable WHERE column2 = somevalue ;

I'm trying to use an array lookup, ala this, that I found in the manual

      ANY/SOME (array)
      expression operator ANY (array expression)

But I'm a newbie to arrays, so I've tried

    DECLARE  myarray             VARCHAR[] := array['''','''']  ;
then in the body
   SELECT INTO myarray ARRAY[column1, column2] from mytable ;

I've discovered via trial and error that the above arrayification works on a simple SQL query without variables.

How can I go about getting a simple variable out of that array on a match on another column?

This query executing thousands of times is killing me!

Thanks,
Ralph