Re: How to hand over array as variable in plpgsql function?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jan Peters" <petersjan(at)gmx(dot)at>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to hand over array as variable in plpgsql function?
Date: 2008-10-28 12:31:04
Message-ID: 18501.1225197064@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Jan Peters" <petersjan(at)gmx(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Higgins 2008-10-28 19:56:28 join table?
Previous Message Peter Eisentraut 2008-10-28 11:59:36 Re: Performing intersection without intersect operator