Re: string cast/compare broken?

Поиск
Список
Период
Сортировка
От Hannu Krosing
Тема Re: string cast/compare broken?
Дата
Msg-id 1026447248.1902.6.camel@rh72.home.ee
обсуждение исходный текст
Ответ на Re: string cast/compare broken?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: string cast/compare broken?
Следующее
От: "Zeugswetter Andreas SB SD"
Дата:
Сообщение: Re: string cast/compare broken?