Re: Text concat Problem

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Luis Magaa <joe666(at)gnovus(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: Text concat Problem
Date: 2000-11-09 03:49:09
Message-ID: Pine.BSF.4.21.0011081945550.40628-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice


On Wed, 8 Nov 2000, Luis [UNKNOWN] Magaa 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 workaround this 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-11-09 04:09:27 Re: Problems dumping a DB
Previous Message Tom Lane 2000-11-09 03:03:05 Re: Relation 'pg_user' does not exist

Browse pgsql-novice by date

  From Date Subject
Next Message rocael 2000-11-09 07:26:11 shared memory blocks?
Previous Message Luis Magaa 2000-11-08 23:49:46 Text concat Problem