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 A96CD9FA5DD for ; Tue, 27 Jun 2006 16:17:48 -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 38402-05 for ; Tue, 27 Jun 2006 16:17:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id DA60A9FA437 for ; Tue, 27 Jun 2006 16:17:37 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k5RJHVc6026696; Tue, 27 Jun 2006 15:17:32 -0400 (EDT) To: Thomas Hallgren cc: Kris Jurka , "Pgsql-Jdbc@Postgresql.Org" Subject: Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject In-reply-to: <44A1739A.2080102@tada.se> References: <44A16388.3060108@tada.se> <44A1739A.2080102@tada.se> Comments: In-reply-to Thomas Hallgren message dated "Tue, 27 Jun 2006 20:06:18 +0200" Date: Tue, 27 Jun 2006 15:17:31 -0400 Message-ID: <26695.1151435851@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/118 X-Sequence-Number: 15398 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