Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 0A5FE9FB71A; Fri, 11 May 2007 10:32:36 -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 32222-01; Fri, 11 May 2007 10:32:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from oxford.xeocode.com (unknown [62.232.55.118]) by postgresql.org (Postfix) with ESMTP id 7B5A29FB865; Fri, 11 May 2007 10:32:30 -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 1HmVEM-00025z-S7; Fri, 11 May 2007 14:32:22 +0100 From: Gregory Stark To: "Tom Lane" Cc: "Michael Meskes" , "PostgreSQL Interfaces" Subject: Re: PQprepare question In-Reply-To: <17526.1178888881@sss.pgh.pa.us> (Tom Lane's message of "Fri, 11 May 2007 09:08:01 -0400") Organization: EnterpriseDB References: <20070511111647.GA18711@feivel.credativ.de> <17526.1178888881@sss.pgh.pa.us> X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.interfaces" 17) Date: Fri, 11 May 2007 14:32:22 +0100 Message-ID: <87ps571o61.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/15 X-Sequence-Number: 6522 "Tom Lane" writes: > Michael Meskes writes: >> According to the docs parameters are referenced as $1, $2, and so. Is >> there a reason not to use "?" as placeholder? > > It's an operator name. Most drivers such as JDBC and DBD::Pg do allow you to use ? parameters because they're the ODBC standard. But they're just replacing them with $1 and so on behind your back. If you want your code to be portable to other databases then it makes sense to use ? But otherwise there are a few advantages to using $1, $2... a) You can change your query to possibly use the arguments in a different order without having to change the execute parameters as well. b) You can use a parameter multiple times in a query without having to burden your execute call site with multiple copies of the parameter. I think you lose if you have an operator ? and want to use these drivers though. Even if you only use $n parameters the driver may still get confused. (At the very least if you ever have a query with no parameters and a ? operator in it). -- Gregory Stark EnterpriseDB http://www.enterprisedb.com