Re: Prepared statement parameters for an 'IN ()' clause

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Prepared statement parameters for an 'IN ()' clause
Date: 2007-10-17 15:25:14
Message-ID: 20071017152513.GI10098@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 17, 2007 at 07:37:15AM -0700, Jason L. Buberel wrote:
> Can someone point me to an example of creating a prepared statement for a
> query with an 'IN' clause?
>
> The query looks like this:
>
> select value from table where
> state = $1 and city = $2 and zip = $3 and
> date in ( $4 );

You're asking here whether "date" matches a single item named by
parameter "4".

> Any quick syntax fix for this?

Try:

date = ANY ($4);

"ANY" treats its parameter as an array, so will accept an array as a
parameter. I've not tried this on a large dataset, so I'm not sure what
sort of performance characteristics you should expect.

Sam

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2007-10-17 15:30:13 Re: Prepared statement parameters for an 'IN ()' clause
Previous Message Josh Trutwin 2007-10-17 15:19:43 Array intersection