Re: [pgsql-advocacy] Oracle buys Innobase

From: "Guy Rouillier" <guyr(at)masergy(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: [pgsql-advocacy] Oracle buys Innobase
Date: 2005-10-19 21:07:23
Message-ID: CC1CF380F4D70844B01D45982E671B239E8BEC@mtxexch01.add0.masergy.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Doug Quale wrote:
> "Marc G. Fournier" <scrappy(at)postgresql(dot)org> writes:
>
>> On Wed, 19 Oct 2005, Richard_D_Levine(at)raytheon(dot)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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Travers 2005-10-19 21:25:58 Oracle and PostgreSQL...
Previous Message Richard_D_Levine 2005-10-19 21:07:03 Re: [pgsql-advocacy] Oracle buys Innobase

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2005-10-19 21:11:30 Re: NULL in IN clause
Previous Message Stephan Szabo 2005-10-19 21:00:03 Re: NULL in IN clause