pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dean Gibson (DB Administrator) <postgresql4@ultimeth.com>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: Blank-padding
Date: Sat, 22 Oct 2005 08:16:48 -0700
Message-ID: <435A57E0.3050006@ultimeth.com> (raw)
In-Reply-To: <27840.1129951428@sss.pgh.pa.us>
References: <CC1CF380F4D70844B01D45982E671B239E8BEC@mtxexch01.add0.masergy.com>
	<878xwokk4d.fsf@charter.net>
	<20051020214518.Q1006@ganymede.hub.org>
	<33c6269f0510210716x474dae2ah3861d32d8db01602@mail.gmail.com>
	<23805.1129913241@sss.pgh.pa.us>
	<435979B0.60107@ultimeth.com>
	<27840.1129951428@sss.pgh.pa.us>

On 2005-10-21 20:23, Tom Lane wrote:
> "Dean Gibson (DB Administrator)" <postgresql4@ultimeth.com> writes:
>   
>> I remember that discussion, and I was for the change.  However, upon 
>> doing some testing after reading the above, I wonder if the 
>> blank-stripping isn't too aggressive.  I have a CHAR(6) field (say, 
>> named Z) that has "abc   " in it.  Suppose I want to append "x" to Z, 
>> with any leading (oops, trailing) spaces in Z PRESERVED.
>>     
>
> (You meant trailing spaces, I assume.)  Why exactly would you want to do that?  You decided by your choice of datatype that the trailing spaces weren't significant.  This gripe seems to me exactly comparable to complaining if a numeric datatype doesn't remember how many trailing zeroes you typed after the decimal point.  Those zeroes aren't semantically significant, so you have no case.
>
> 			regards, tom lane
>   

It's one thing, as with floating point values, where the internal 
representation is identical (1.0 stored identically to 1.00), and 
another thing where the internal representation is different (a la 
strings storing 'abc   ' differently from 'abc'.  While programming 
languages may differ as to how they compare those two strings, every one 
that I'm familiar with does not strip trailing spaces when concatenating.

It's not an issue with me, but the 8.0 concatenation does violate the 
"Principle of Least Astonishment".  As does treating 'abc   ' and 'abc' 
different during comparisons (which 8.0 fixed).

So my tentative argument would be, strip trailing spaces on CHAR(n) 
comparisons but not on concatenation or assignment, because you lost 
information.  You can always strip if you need to (as you do in other 
languages).

As I said, this issue doesn't presently affect my databases, it's just 
an observation.

-- Dean



view thread (5+ messages)  latest in thread

Message-ID: <435A57E0.3050006@ultimeth.com>
Permalink:  ../435A57E0.3050006@ultimeth.com/
Also on:    postgresql.org/message-id/435A57E0.3050006@ultimeth.com

 · 

reply

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: postgresql4@ultimeth.com
  Subject: Re: Blank-padding
  In-Reply-To: <435A57E0.3050006@ultimeth.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