pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Hallgren <thomas@tada.se>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Kris Jurka <books@ejurka.com>
Cc: Pgsql-Jdbc@Postgresql.Org <pgsql-jdbc@postgresql.org>
Subject: Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject
Date: Tue, 27 Jun 2006 21:43:15 +0200
Message-ID: <44A18A53.5000107@tada.se> (raw)
In-Reply-To: <26695.1151435851@sss.pgh.pa.us>
References: <44A16388.3060108@tada.se>
	<Pine.BSO.4.63.0606271211590.8616@leary2.csoft.net>
	<44A1739A.2080102@tada.se>
	<26695.1151435851@sss.pgh.pa.us>

Tom Lane wrote:
> Thomas Hallgren <thomas@tada.se> 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





view thread (10+ messages)  latest in thread

Message-ID: <44A18A53.5000107@tada.se>
Permalink:  ../44A18A53.5000107@tada.se/
Also on:    postgresql.org/message-id/44A18A53.5000107@tada.se

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: thomas@tada.se, tgl@sss.pgh.pa.us, books@ejurka.com
  Subject: Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject
  In-Reply-To: <44A18A53.5000107@tada.se>
  References: <44A16388.3060108@tada.se> <Pine.BSO.4.63.0606271211590.8616@leary2.csoft.net> <44A1739A.2080102@tada.se> <26695.1151435851@sss.pgh.pa.us> <44A18A53.5000107@tada.se>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox