Re: string cast/compare broken?

From: Hannu Krosing <hannu(at)tm(dot)ee>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Scott Royston <scroyston(at)mac(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: string cast/compare broken?
Date: 2002-07-12 04:14:07
Message-ID: 1026447248.1902.6.camel@rh72.home.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 2002-07-12 at 08:50, Tom Lane wrote:
> Scott Royston <scroyston(at)mac(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Lockhart 2002-07-12 05:34:27 Re: I am being interviewed by OReilly
Previous Message Tom Lane 2002-07-12 03:50:25 Re: string cast/compare broken?