Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-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

pgsql-hackers by date

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

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group