Re: CHAR(n) always trims trailing spaces in 7.4

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
Cc: elein <elein(at)varlena(dot)com>, "news(dot)postgresql(dot)org" <jlim(at)natsoft(dot)com(dot)my>, pgsql-sql(at)postgresql(dot)org
Subject: Re: CHAR(n) always trims trailing spaces in 7.4
Date: 2004-02-18 00:25:47
Message-ID: 19236.1077063947@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

"scott.marlowe" <scott(dot)marlowe(at)ihs(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message elein 2004-02-18 00:27:13 Re: CHAR(n) always trims trailing spaces in 7.4
Previous Message terry 2004-02-18 00:23:44 Re: CHAR(n) always trims trailing spaces in 7.4

Browse pgsql-sql by date

  From Date Subject
Next Message elein 2004-02-18 00:27:13 Re: CHAR(n) always trims trailing spaces in 7.4
Previous Message terry 2004-02-18 00:23:44 Re: CHAR(n) always trims trailing spaces in 7.4