Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D95959FC14F for ; Fri, 11 May 2007 09:31:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 85457-01 for ; Fri, 11 May 2007 09:31:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from oxford.xeocode.com (unknown [62.232.55.118]) by postgresql.org (Postfix) with ESMTP id 2FF909FC143 for ; Fri, 11 May 2007 09:31:33 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1HmUHP-00024D-Mz; Fri, 11 May 2007 13:31:27 +0100 From: Gregory Stark To: "Andrew McNamara" Cc: Subject: Re: PQexecParams and IN query? In-Reply-To: <20070511120332.6F61C5CC4B5@longblack.object-craft.com.au> (Andrew McNamara's message of "Fri, 11 May 2007 22:03:32 +1000") Organization: EnterpriseDB References: <20070511120332.6F61C5CC4B5@longblack.object-craft.com.au> X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.interfaces" 15) Date: Fri, 11 May 2007 13:31:27 +0100 Message-ID: <87tzuj1qzk.fsf@oxford.xeocode.com> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/12 X-Sequence-Number: 6519 "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. 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