Re: [pgsql-advocacy] Oracle buys Innobase

From: Alex Turner <armtuk(at)gmail(dot)com>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: Doug Quale <quale1(at)charter(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: [pgsql-advocacy] Oracle buys Innobase
Date: 2005-10-21 14:16:08
Message-ID: 33c6269f0510210716x474dae2ah3861d32d8db01602@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

It appears that casting to a char() causes spaces to be stripped (ignored)
from the string:
mls=# select length('123 '::char(8));
length
--------
3
(1 row)

mls=# select length('123 '::char(8)::varchar(8));
length
--------
3
(1 row)

but:
mls=# select length('123 '::varchar(8));
length
--------
6
(1 row)

I'm not sure about anyone else, but I would personaly consider that a bug?
Should the length function return the correct length of a fixed length
string, or the length of significant characters? What does the SQL standard
say on this one? I googled it a bit, but didn't come up with much.

Alex Turner
NetEconomist

On 10/20/05, Marc G. Fournier <scrappy(at)postgresql(dot)org> wrote:
>
> On Thu, 20 Oct 2005, Doug Quale wrote:
>
> > "Guy Rouillier" <guyr(at)masergy(dot)com> writes:
> >
> >> Doug Quale wrote:
> >>>
> >>> # 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.
> >
> > Huh??? What version of PG are you using? On 7.4.9,
> >
> >
> > test=# select length('a'::char(8));
> > length
> > --------
> > 8
> > (1 row)
> >
> > test=# select length('a '::char(8));
> > length
> > --------
> > 8
> > (1 row)
> >
> > The truncation you describe would simply be wrong.
>
> ams=# select length('a '::char(8));
> length
> --------
> 1
> (1 row)
>
> ams=# select version();
> version
> ----------------------------------------------------------------------
> PostgreSQL 8.0.2 on i386-portbld-freebsd4.11, compiled by GCC 2.95.4
> (1 row)
>
> ams=#
>
>
> ----
> Marc G. Fournier Hub.Org Networking Services (http://www.hub.org)
> Email: scrappy(at)hub(dot)org Yahoo!: yscrappy ICQ: 7615664
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tino Wildenhain 2005-10-21 14:21:16 Re: PSQL suggested enhancement
Previous Message Magnus Hagander 2005-10-21 14:10:16 Re: password

Browse pgsql-sql by date

  From Date Subject
Next Message gurkan 2005-10-21 14:19:51 SQL Functions
Previous Message Wiebe Cazemier 2005-10-21 14:13:47 Delete rule chain stops unexpectedly