| From: | Thomas Hallgren <thomas(at)tada(dot)se> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | Kris Jurka <books(at)ejurka(dot)com>, "Pgsql-Jdbc(at)Postgresql(dot)Org" <pgsql-jdbc(at)postgresql(dot)org> |
| Subject: | Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject |
| Date: | 2006-06-27 19:43:15 |
| Message-ID: | 44A18A53.5000107@tada.se |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
Tom Lane wrote:
> Thomas Hallgren <thomas(at)tada(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2006-06-27 21:07:56 | Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject |
| Previous Message | Tom Lane | 2006-06-27 19:17:31 | Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject |