Re: Stupid question: concatenating strings

Thomas Good <tomg@q8.nrnet.org>

From: Thomas Good <tomg@q8.nrnet.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: justinlong@strategicnetwork.org, pgsql-novice@hub.org
Date: 2000-10-18T17:46:08Z
Lists: pgsql-novice
On Wed, 18 Oct 2000, Tom Lane wrote:

>> I can't figure out how to do this.
>> 
>> I want to do the following
>> 
>> UPDATE newlink SET newfrom = substr(oldfrom,0,1) + '-' + substr(oldfrom,1)

> The string concatenation operator in SQL is ||, not +.
> 
> Also, substr's start-index argument counts from 1 not 0.  Otherwise
> you've got the right idea...
> 
> 			regards, tom lane


Tom,

The || operator needs parentheses to concat > 2 items in Pg 6.3.2.  
Has this been fixed in subsequent versions?

If not, for Justin - this is what I do to concat more than
two items... 

select (staff_fname || staff_lname) || ('-' || staff_ssn) 
as "Social Security" 
from personnel 
where staff_id = 1000;

Cheers,
Tom Good

--------------------------------------------------------------------
               SVCMC - Center for Behavioral Health                  
--------------------------------------------------------------------
Thomas Good                          tomg@ { admin | q8 } .nrnet.org
IS Coordinator / DBA                 Phone: 718-354-5528 
                                     Fax:   718-354-5056  
--------------------------------------------------------------------
Powered by:  PostgreSQL     s l a c k w a r e          FreeBSD:
               RDBMS       |---------- linux      The Power To Serve
--------------------------------------------------------------------