Re: Prepared statements with a variable number of parameters

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Prepared statements with a variable number of parameters
Date: 2009-10-10 21:37:07
Message-ID: 4AD0FE83.90105@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/10/2009 18:52, Pavel Stehule wrote:

> 2009/10/10 Raymond O'Donnell <rod(at)iol(dot)ie>:

>> My question is, what do people normally do when there's a variable
>> number of parameters? - for example:
>>
>> select ..... where item_id in ( ... );
>>
>
> You can use arrays here.
>
> select ... where item_id = ANY(string_to_array($1, ','))

Nice one! Thanks Pavel.

My item_id values are integers, so I added ::integer[] to the above and
all works nicely:

...where item_id = any(string_to_array($1, ',')::integer[])

Thanks again,

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Landscheidt 2009-10-10 22:30:50 Re: What's wrong with this regexp?
Previous Message Adrian Klaver 2009-10-10 21:15:53 Re: How to send multiple SQL commands from Python?