X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9D6949FA502 for ; Tue, 27 Jun 2006 16:43:32 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 49463-08 for ; Tue, 27 Jun 2006 16:43:21 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tada.se (1-1-2-48a.rny.sth.bostream.se [82.182.133.12]) by postgresql.org (Postfix) with ESMTP id 7C6ED9FA10A for ; Tue, 27 Jun 2006 16:43:18 -0300 (ADT) Received: from [127.0.0.1] (unverified [127.0.0.1]) by tada.se (SurgeMail 3.7b3) with ESMTP id 492 for multiple; Tue, 27 Jun 2006 21:43:15 +0200 Message-ID: <44A18A53.5000107@tada.se> Date: Tue, 27 Jun 2006 21:43:15 +0200 From: Thomas Hallgren User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Tom Lane CC: Kris Jurka , "Pgsql-Jdbc@Postgresql.Org" Subject: Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject References: <44A16388.3060108@tada.se> <44A1739A.2080102@tada.se> <26695.1151435851@sss.pgh.pa.us> In-Reply-To: <26695.1151435851@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Server: High Performance Mail Server - http://surgemail.com r=849097733 X-Authenticated-User: thomas@tada.se X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/119 X-Sequence-Number: 15399 Tom Lane wrote: > Thomas Hallgren writes: > >> so why does it make a difference to use varchar instead of text? >> > > It's a question of type resolution rules. text is the preferred string > type so it "wins" in cross-type situations, in particular > char_value = text_value > will be interpreted as > char_value::text text_eq text_value > varchar is not only not a preferred type, it doesn't even have any > comparison ops of its own (it depends on text's ops). Therefore given > char_value = varchar_value > the parser is faced with the alternative interpretations > char_value::text text_eq varchar_value::text > char_value char_eq varchar_value::char > and it will prefer the latter because it has fewer casts. > See > http://www.postgresql.org/docs/8.1/static/typeconv.html > particularly rules 10.2.3b and 3c. The upshot of all this > is that a parameter specified as "text" dominates any comparison > to other string datatypes, whereas one specified as "varchar" > does not. Yeah, it's a bit grotty, but it gets the job done > and it's not an area we're likely to change much. > > regards, tom lane > Hmm, OK. I checked my code and I don't use any specific type. Instead, I use SPI_getargtypeid(ePlan, idx) on the prepared query and the pgType->typinput function of the type that corresponds to the returned oid. Perhaps the SPI_getargtypeid should return varchar for all text types? Regards, Thomas Hallgren