Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject - Mailing list pgsql-jdbc

From Thomas Hallgren
Subject Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject
Date
Msg-id 44A1739A.2080102@tada.se
Whole thread Raw
In response to Re: [Fwd: Re: [Pljava-dev] char with trailing space,  (Kris Jurka <books@ejurka.com>)
Responses Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject
List pgsql-jdbc
Kris Jurka wrote:
>
> The JDBC driver does not trim spaces.  What it does is pass
> setString() values with a type of varchar, perhaps pljava is using
> text and exposing this subtle difference:
>
> # select 'a '::char(2) = 'a '::text;
>  ?column?
> ----------
>  f
> (1 row)
> # select 'a '::char(2) = 'a '::varchar;
>  ?column?
> ----------
>  t
> (1 row)
>
I'm missing something. Both text and varchar consider the space significant:


thhal=# select length(' '::char);
 length
--------
      0
(1 row)

thhal=# select length(' '::varchar);
 length
--------
      1
(1 row)

thhal=# select length(' '::text);
 length
--------
      1
(1 row)

so why does it make a difference to use varchar instead of text? I.e.
why are your comparison results different? Why is the space
insignificant when using char?

Regards,
Thomas Hallgren


pgsql-jdbc by date:

Previous
From: Kris Jurka
Date:
Subject: Re: [Fwd: Re: [Pljava-dev] char with trailing space,
Next
From: Tom Lane
Date:
Subject: Re: [Fwd: Re: [Pljava-dev] char with trailing space, PreparedStatement.setObject