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

Re: Significant spaces

From: mike g <mike(at)thegodshalls(dot)com>
To: Steve Tucknott <steve(at)retsol(dot)co(dot)uk>
Cc: PostGre <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Significant spaces
Date: 2004-07-31 04:12:40
Message-ID: 1091247160.3676.4.camel@localhost.localdomain (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
The char data type will automatically pad unused positions with space so
it stays fixed at 250.

Varchar will automatically trim any unused positions.

I assume in your code somewhere you are doing a CAST(char column as
varchar).  You can enclose this in a TRIM to remove whitespace at
beginning and end.  TRIM(CAST(char column as varchar))

On Fri, 2004-07-30 at 07:35, Steve Tucknott wrote:
> PostGreSQL 7.2.4 
> Can anyone tell me where trailing spaces are significant in CHAR,
> VARCHAR and TEXT fields? 
> We pass a VARCHAR variable into a 3rd party language product
> 'function' as a CHAR(250). The CHAR(250) field is then used to
> interrogate a table to see if that value exists. If not, a row with
> that value is inserted into the table as a VARCHAR(N). The issue is
> that the value when inserted into the VARCHAR in the table appears to
> carry trailing spaces, so when a subsequent lookup is performed with
> the same value, the value is not 'found' and a further insert occurs. 
> The problem appears to disappear if I change the definition of the
> passed parameter to a VARCHAR as well. 
> Is this a known issue? 
> Regards,
> Steve Tucknott
> ReTSol Ltd
> DDI: 01903 828769

In response to


pgsql-novice by date

Next:From: Frank BaxDate: 2004-07-31 13:11:14
Subject: Re: Significant spaces
Previous:From: Jeffrey MelloyDate: 2004-07-30 17:45:55
Subject: Re: trying to run a query

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