Re: CHAR(n) always trims trailing spaces in 7.4 - Mailing list pgsql-sql

From Tom Lane
Subject Re: CHAR(n) always trims trailing spaces in 7.4
Date
Msg-id 19236.1077063947@sss.pgh.pa.us
Whole thread Raw
In response to Re: CHAR(n) always trims trailing spaces in 7.4  ("scott.marlowe" <scott.marlowe@ihs.com>)
Responses Re: CHAR(n) always trims trailing spaces in 7.4  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
"scott.marlowe" <scott.marlowe@ihs.com> writes:
> But then this:
> select 'x'||' '||'x'
> should produce xx, but it produces x x.

No, because the imputed type of those literals is text.  You'd have to
cast the middle guy to char(n) explicitly to make its trailing spaces go
away when it's reconverted to text.

The real issue here is that trailing spaces in char(n) are semantically
insignificant according to the SQL spec.  The spec is pretty vague about
which operations should actually honor that insignificance --- it's
clear that comparisons should, less clear about other things.  I think
the 7.4 behavior is more consistent than what we had before, but I'm
willing to be persuaded to change it again if someone can give an
alternate definition that's more workable than this one.
        regards, tom lane


pgsql-sql by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: CHAR(n) always trims trailing spaces in 7.4
Next
From:
Date:
Subject: Re: CHAR(n) always trims trailing spaces in 7.4