From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gregory Stark <stark@enterprisedb.com>
Cc: Andrew McNamara <andrewm@object-craft.com.au>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: PQexecParams and IN query?
Date: Fri, 11 May 2007 09:12:46 -0400
Message-ID: <17601.1178889166@sss.pgh.pa.us> (raw)
In-Reply-To: <87tzuj1qzk.fsf@oxford.xeocode.com>
References: <20070511120332.6F61C5CC4B5@longblack.object-craft.com.au>
<87tzuj1qzk.fsf@oxford.xeocode.com>
Gregory Stark <stark@enterprisedb.com> writes:
> "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.
Be aware also that if you're hoping that this will use an index on
colvalue, you need 8.2 or later to get such a plan from an "= any"
construct.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: tgl@sss.pgh.pa.us, stark@enterprisedb.com, andrewm@object-craft.com.au
Subject: Re: PQexecParams and IN query?
In-Reply-To: <17601.1178889166@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox