Re: [GENERAL] Text concat Problem - Mailing list pgsql-novice

From Stephan Szabo
Subject Re: [GENERAL] Text concat Problem
Date
Msg-id Pine.BSF.4.21.0011081945550.40628-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Text concat Problem  (Luis Magaña <joe666@gnovus.com>)
List pgsql-novice
On Wed, 8 Nov 2000, Luis [UNKNOWN] Maga�a wrote:

> insert into employee(title,first_name,start_date,charge) values('Mr. X','Smith',date(now()),'None');
> insert into employee(title,first_name,start_date,charge) values('Mr. Y','Smith',date(now()),'None');
> insert into employee(title,first_name,start_date,charge) values('Mr. Z','Smith',date(now()),'None');
>
> so far there is no problem at all, the problem comes here:
>
> select title || ' ' || first_name || ' ' || last_name as fullname from employee;
>
>    fullname
> ----------------
>
>
>
>  (3 rows)
>
> Doesn't work !!!!, I'm thinking it is because of the null value in last_name.  Have any idea or suggestion on how to
workaroundthis situation. 

Yes, use coalesce(<fieldname>, '') instead of fieldname.
So,
select coalesce(title, '') || ' ' || coalesce(first_name, '')
 || ' ' || coalesce(last_name, '') as fullname from employee;

SQL defines concatenation of a string value and NULL to be NULL.


pgsql-novice by date:

Previous
From: ghaverla@freenet.edmonton.ab.ca
Date:
Subject: Compiling 7.0.2 and this mailing list
Next
From: "Diego A. Puertas F."
Date:
Subject: psql won't start