dbTalk Databases Forums  

String Concatenation

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


Discuss String Concatenation in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Luiz K. Matsumura
 
Posts: n/a

Default String Concatenation - 07-23-2004 , 11:00 AM






I want to concatenate 2 fields :
tpmov char(4) | dsmov char(10)
---------------+----------------
AB | SOMETHING

If I do:

SELECT tpmov || dsmov as History ...

if the field tpmov has a fixed lenght of char(4) the result
expected (I suppose) may be

History
--------------
AB SOMETHING

But Postgres returns

History
------------
ABSOMETHING

Why this occurs ?
How I can get the first result ( AB__SOMETHING ) ?

If I do a select with the literal strings the result is as expected :

SELECT 'AB ' || 'SOMETHING' AS History ;

History
--------------
AB SOMETHING

My reasoning is wrong or this is a bug ?



Reply With Quote
  #2  
Old   
John Brookes
 
Posts: n/a

Default Re: String Concatenation - 07-23-2004 , 11:49 AM







----- Original Message -----
From: Luiz K. Matsumura
To: pgsql-novice (AT) postgresql (DOT) org
Sent: Friday, July 23, 2004 9:00 AM
Subject: [NOVICE] String Concatenation


I want to concatenate 2 fields :
tpmov char(4) | dsmov char(10)
---------------+----------------
AB | SOMETHING

If I do:

SELECT tpmov || dsmov as History ...

if the field tpmov has a fixed lenght of char(4) the result
expected (I suppose) may be

History
--------------
AB SOMETHING

But Postgres returns

History
------------
ABSOMETHING

Why this occurs ?
How I can get the first result ( AB__SOMETHING ) ?

If I do a select with the literal strings the result is as expected :

SELECT 'AB ' || 'SOMETHING' AS History ;

History
--------------
AB SOMETHING

My reasoning is wrong or this is a bug ?



Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: String Concatenation - 07-23-2004 , 12:56 PM



"Luiz K. Matsumura" <luiz (AT) planit (DOT) com.br> writes:
Quote:
My reasoning is wrong or this is a bug ?
This is a debatable issue. See the thread starting here:
http://archives.postgresql.org/pgsql...7/msg00156.php
for some recent debate. (What is not brought out in that particular
thread is that our pre-7.4 behavior was also surprising, just in
different places. Trawling the archives for awhile may convince you
that 7.4 is better, or not.)

The bottom line in my mind is that the SQL spec's treatment of padding
space characters is very inconsistent, and so you're best off to use a
datatype that doesn't consider trailing spaces as special --- ie, use
varchar or text, and avoid char(n) like the plague.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



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.