Re: string cast/compare broken? - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: string cast/compare broken?
Date
Msg-id 1026447248.1902.6.camel@rh72.home.ee
Whole thread Raw
In response to Re: string cast/compare broken?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Fri, 2002-07-12 at 08:50, Tom Lane wrote:
> Scott Royston <scroyston@mac.com> writes:
> > [ various examples of comparing char and varchar ]
> 
> I see no bug here.  For the CHAR datatype, trailing spaces are defined
> to be insignificant.  For VARCHAR and TEXT, trailing spaces are
> significant.  If you want to compare a CHAR value to a VARCHAR or TEXT
> value, your best bet is a locution like
>     rtrim(charval) = varcharval

I guess the strangest part was that both a.foo = 'S' and b.foo = 'S' but
not a.foo=b.foo;  (a.foo is varchar(5) , b.foo is char(5) )

I guess that tha 'S' that b.foo gets compared to is converted to 'S    '
before comparison but when comparing varchar(5) and char(5) they are
both compared by converting them to varchar which keeps the trailing
spaces from char(5). If the conversion where varchar(5) --> char(5) then
they would compare equal.

I vaguely remember something in the standard about cases when comparing
char() types should discard extra spaces.

-------------
Hannu





pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: string cast/compare broken?
Next
From: "Zeugswetter Andreas SB SD"
Date:
Subject: Re: string cast/compare broken?