dbTalk Databases Forums  

Significant spaces

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Significant spaces in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Steve Tucknott
 
Posts: n/a

Default Significant spaces - 07-30-2004 , 07:35 AM






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



Reply With Quote
  #2  
Old   
mike g
 
Posts: n/a

Default Re: Significant spaces - 07-30-2004 , 11:12 PM






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))

HTH
On Fri, 2004-07-30 at 07:35, Steve Tucknott wrote:
Quote:
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
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #3  
Old   
Frank Bax
 
Posts: n/a

Default Re: Significant spaces - 07-31-2004 , 08:11 AM



At 12:12 AM 7/31/04, mike g wrote:
Quote:
Varchar will automatically trim any unused positions.

varchar doesn't 'trim' anything - it inserts text exactly as it is coded.


fbax=# create table vctest( c1 varchar );
CREATE
fbax=# insert into vctest values('abc ');
INSERT 11939819 1
fbax=# insert into vctest values('abcd');
INSERT 11939820 1
fbax=# select *,length(c1) from vctest where c1~' $';
c1 | length
--------+--------
abc | 6
(1 row)



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.