From: Richard Huxton <dev@archonet.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: scott.marlowe <scott.marlowe@ihs.com>
Cc: elein <elein@varlena.com>
Cc: news.postgresql.org <jlim@natsoft.com.my>
Cc: pgsql-sql@postgresql.org
Subject: Re: CHAR(n) always trims trailing spaces in 7.4
Date: Wed, 18 Feb 2004 09:40:16 +0000
Message-ID: <200402180940.16896.dev@archonet.com> (raw)
In-Reply-To: <19236.1077063947@sss.pgh.pa.us>
References: <Pine.LNX.4.33.0402171706530.31955-100000@css120.ihs.com>
<19236.1077063947@sss.pgh.pa.us>
On Wednesday 18 February 2004 00:25, Tom Lane wrote:
> "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.
[rant on]
I've never really understood the rationale behind char(n) in SQL databases
(other than as backward compatibility with some old mainframe DB).
Insignificant spaces? If it's not significant, why is it there? You could
have a formatting rule that specifies left-aligned strings space-padded (as
printf) but that's not the same as mucking about appending and trimming
spaces.
The only sensible definition of char(n) that I can see would be:
A text value of type char(n) is always "n" characters in length. If you assign
less than "n" characters, it is right-padded with spaces. In all other
respects it behaves as any other text type of length "n" with right-trailing
spaces.
[rant off - ah, feel better for that :-]
--
Richard Huxton
Archonet Ltd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: dev@archonet.com, tgl@sss.pgh.pa.us, scott.marlowe@ihs.com, elein@varlena.com, jlim@natsoft.com.my
Subject: Re: CHAR(n) always trims trailing spaces in 7.4
In-Reply-To: <200402180940.16896.dev@archonet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox