Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 344CD9FC02F for ; Fri, 11 May 2007 10:12:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 28959-08 for ; Fri, 11 May 2007 10:12:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4E4B19FC163 for ; Fri, 11 May 2007 10:12:55 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l4BDCk0A017602; Fri, 11 May 2007 09:12:46 -0400 (EDT) To: Gregory Stark cc: "Andrew McNamara" , pgsql-interfaces@postgresql.org Subject: Re: PQexecParams and IN query? In-reply-to: <87tzuj1qzk.fsf@oxford.xeocode.com> References: <20070511120332.6F61C5CC4B5@longblack.object-craft.com.au> <87tzuj1qzk.fsf@oxford.xeocode.com> Comments: In-reply-to Gregory Stark message dated "Fri, 11 May 2007 13:31:27 +0100" Date: Fri, 11 May 2007 09:12:46 -0400 Message-ID: <17601.1178889166@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/14 X-Sequence-Number: 6521 Gregory Stark writes: > "Andrew McNamara" 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