Unix Technical Forum

How to concat strings so that trailing spaces remain

This is a discussion on How to concat strings so that trailing spaces remain within the Pgsql General forums, part of the PostgreSQL category; --> I have where clause where all fields are CHAR(10) type and may have trailing spaces. SELECT ... FROM r1, ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 09:03 AM
Andrus
 
Posts: n/a
Default How to concat strings so that trailing spaces remain

I have where clause where all fields are CHAR(10) type and may have trailing
spaces.

SELECT ...

FROM r1, r2

WHERE r1.c1 || r1.c2 || r1.c3 >= r2.c1 || r2.c2 || r2.c3;



This WHERE clause produces wrong result since || operator removes trailing
spaces.

Correct result is produced if || operator does not remove trailing spaces.

How to concat strings in this expression so that trailing spaces are
significiant or how to re-write this join condition so that trailing spaces
are used for comparison?

Andrus.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 09:03 AM
Tom Lane
 
Posts: n/a
Default Re: How to concat strings so that trailing spaces remain

"Andrus" <eetasoft@online.ee> writes:
> I have where clause where all fields are CHAR(10) type and may have trailing
> spaces.
> ...
> Correct result is produced if || operator does not remove trailing spaces.


If you think that trailing spaces are significant data, you should
probably be using VARCHAR not CHAR datatype.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 09:03 AM
Andrus
 
Posts: n/a
Default Re: How to concat strings so that trailing spaces remain

> If you think that trailing spaces are significant data, you should
> probably be using VARCHAR not CHAR datatype.


I have existing database where there are only CHAR columns, no any VARCHAR
column.
I'm not sure will my appl work if I change all char columns to varchar
columns .
Is it reasonable to change all occurences of CHAR to VARCHAR in database ?


Are the following clauses exactly same for fields of type CHAR(10):

WHERE r1.c1::VARCHAR(10) || r1.c2::VARCHAR(10) || r1.c3::VARCHAR(10) >=
r2.c1::VARCHAR(10) || r2.c2::VARCHAR(10) ||
r2.c3::VARCHAR(10)

and

WHERE r1.c1>=r2.c1 and r1.c2>=r2.c2 and r1.c3>=r2.c3

and

WHERE (r1.c1, r1.c2,r1.c3) >= (r2.c1, r2.c2,r2.c3)

Andrus.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:43 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com