Re: PQexecParams and IN query? - Mailing list pgsql-interfaces

From Gregory Stark
Subject Re: PQexecParams and IN query?
Date
Msg-id 87tzuj1qzk.fsf@oxford.xeocode.com
Whole thread Raw
In response to PQexecParams and IN query?  (Andrew McNamara <andrewm@object-craft.com.au>)
Responses Re: PQexecParams and IN query?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-interfaces
"Andrew McNamara" <andrewm@object-craft.com.au> writes:

> I'm trying to use PQexecParams to do an "IN" query, where the set of
> values is supplied as a single parameter - essentially:
>
>     SELECT * FROM sometable WHERE colvalue IN $1
>
> With $1 as a set or array of some sort. Unfortunately, the above doesn't
> pass parsing.  Is there any way to do an IN query via PQexecParams that
> doesn't involve enumerating the set of values as individual parameters?

No but there is a way to do something equivalent with arrays:

SELECT * FROM sometable WHERE colvalue = any($1::integer[]);

I'm not sure which (if any) drivers have good support for arrays though. I
think with most if not all drivers you'll have to crunch your list of elements
down into a string argument of the form "{1,2,3}" (without the quotes). 

If you're using something more complex than integers then you'll have to deal
with quoting the array elements which will start to get annoying.

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com



pgsql-interfaces by date:

Previous
From: Andrew McNamara
Date:
Subject: PQexecParams and IN query?
Next
From: Tom Lane
Date:
Subject: Re: PQprepare question