Re: [pgsql-advocacy] Oracle buys Innobase - Mailing list pgsql-general

From Guy Rouillier
Subject Re: [pgsql-advocacy] Oracle buys Innobase
Date
Msg-id CC1CF380F4D70844B01D45982E671B239E8BEC@mtxexch01.add0.masergy.com
Whole thread Raw
Responses Re: [pgsql-advocacy] Oracle buys Innobase  (Doug Quale <quale1@charter.net>)
List pgsql-general
Doug Quale wrote:
> "Marc G. Fournier" <scrappy@postgresql.org> writes:
>
>> On Wed, 19 Oct 2005, Richard_D_Levine@raytheon.com wrote:
>>
>>> I was referring to trailing blanks, but did not explicitly say it,
>>> though showed it in the examples.  I am pretty sure that the SQL
>>> standard says that trailing whitespace is insignificant in string
>>> comparison.
>>
>> Then we are broken too :)
>>
>> # select 'a ' = 'a  ';
>>   ?column?
>> ----------
>>   f
>> (1 row)
>
> # select 'a'::char(8) = 'a '::char(8);
>  ?column?
> ----------
>  t
> (1 row)
>
> Trailing blanks aren't significant in fixed-length strings, so the
> question is whether Postgresql treats comparison of varchars right.

This result is being misinterpreted.

select length('a'::char(8)) ==> 1
select length('a '::char(8)) ==> 1

So it isn't that the two different strings are comparing equal.  The
process of casting them to char(8) is trimming the blanks, so by the
time they become fixed length strings, they are indeed equal.

Addressing Dan's subsequent note here, I tried this in Oracle:

select length(cast('a ' as varchar2(30))) from dual ==> 2

So Oracle does not trim when it casts.  The subject of whether casting
should trim trailing blanks is yet another tangential discussion.  I
would say that if the user hasn't specifically asked for a trim, it
shouldn't happen, but I have not read the standard on this.

We're all discussing these intricacies from a comp sci perspective.
From a normal user's perspective, of course, they would prefer the DBMS
to hide these types of nuances.

--
Guy Rouillier

pgsql-general by date:

Previous
From: "Dann Corbit"
Date:
Subject: Re: 'a' == 'a ' (Was: RE: [pgsql-advocacy] Oracle buysInnobase)
Next
From: Richard_D_Levine@raytheon.com
Date:
Subject: Re: [pgsql-advocacy] Oracle buys Innobase