Skip site navigation (1) Skip section navigation (2)

Re: PQexecParams and IN query?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: "Andrew McNamara" <andrewm(at)object-craft(dot)com(dot)au>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQexecParams and IN query?
Date: 2007-05-11 13:12:46
Message-ID: 17601.1178889166@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-interfaces
Gregory Stark <stark(at)enterprisedb(dot)com> writes:
> "Andrew McNamara" <andrewm(at)object-craft(dot)com(dot)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

In response to

pgsql-interfaces by date

Next:From: Gregory StarkDate: 2007-05-11 13:32:22
Subject: Re: PQprepare question
Previous:From: Tom LaneDate: 2007-05-11 13:08:01
Subject: Re: PQprepare question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group