Re: How to hand over array as variable in plpgsql function? - Mailing list pgsql-sql

From Tom Lane
Subject Re: How to hand over array as variable in plpgsql function?
Date
Msg-id 18501.1225197064@sss.pgh.pa.us
Whole thread Raw
In response to Re: How to hand over array as variable in plpgsql function?  ("Jan Peters" <petersjan@gmx.at>)
List pgsql-sql
"Jan Peters" <petersjan@gmx.at> writes:
>> Seems like using EXECUTE is the hardest possible way to do this.  Why
>> don't you just SELECT?
>> 
>> SELECT id FROM precip_arrays WHERE b = precip_control INTO id_result;

> How should the code look like to do this?

Uh ... just like that.

> SELECT precip_control FROM precip_arrays WHERE  id = 400; --returns an array
> SELECT id FROM precip_arrays WHERE [THE RETURNED ARRAY] = precip_scenario;--compares the above array to the arrays in
colum"precip_scenario". 
 

Sure, SELECT precip_control INTO some_local_array_variable FROM ...
and then use the variable in the next command.

> This obviously does NOT work:

> SELECT id FROM precip_arrays WHERE (SELECT precip_control FROM precip_arrays WHERE  id = 400;) = precip_control;

Well, it would if you got rid of the first semicolon, although most
people would prefer to write this as a join.
        regards, tom lane


pgsql-sql by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Performing intersection without intersect operator
Next
From: Michael Higgins
Date:
Subject: join table?