Re: 7.4: CHAR padding inconsistency

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Troels Arvin <troels(at)arvin(dot)dk>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: 7.4: CHAR padding inconsistency
Date: 2003-11-19 19:50:24
Message-ID: 200311191950.hAJJoOR16098@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Troels Arvin wrote:
> Hello,
>
> I read about the padding-of-CHAR-values changes in the release notes for
> 7.4.
>
> Making PostgreSQL less standard compliant is sad; I also disagree
> with the statement that trimming of trailing white-space is what people
> expect.
>
> What's worse, and this may be classified as an error:
>
> create table chartest(col char(10) not null);
> insert into chartest values ('AAA');
>
> select character_length(col) from chartest;
> character_length
> ------------------
> 10
>
> select character_length(col || 'hey') from chartest;
> character_length
> ------------------
> 6
>
> SELECT CHARACTER_LENGTH(col) <
> CHARACTER_LENGTH(col||'hey') from chartest;
> ?column?
> ----------
> f
>
> The last two results are horrifying, in my opinion, especially when you
> consider them in concert: Concatenating a value with another value
> decreases its length...

Horrifying?

Anyway, what did you want it to output? "AAA hey"? We could do
that, but I assume most people wouldn't expect that output? If you use
literals it does work:

test=> SELECT 'aaa ' || 'bb';
?column?
----------
aaa bb
(1 row)

I tried this and it clipped too:

test=> SELECT CAST('aa ' AS CHAR(10)) || 'b';
?column?
----------
aab
(1 row)

How do other databases handle this?

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alex Albarracin 2003-11-19 20:26:34 memory bug
Previous Message Troels Arvin 2003-11-19 02:55:09 7.4: CHAR padding inconsistency

Browse pgsql-hackers by date

  From Date Subject
Next Message Hans-Jürgen Schönig 2003-11-19 19:57:03 Re: Commercial binary support?
Previous Message Robert Treat 2003-11-19 19:35:35 Re: Is there going to be a port to Solaris 9 x86 in the