Re: Concatenating not working properly - Mailing list pgsql-sql

From Joe Conway
Subject Re: Concatenating not working properly
Date
Msg-id 3E9439AF.9090505@joeconway.com
Whole thread Raw
In response to Concatenating not working properly  (Michal Taborsky <M.Taborsky@sh.cvut.cz>)
List pgsql-sql
Michal Taborsky wrote:
> akcent=# SELECT (surname || ', ' || firstname || ' ' || secondname) as 
> fullname, title_pre, surname, firstname, secondname FROM person;
> 
>        fullname        | title_pre | surname  | firstname | secondname
> -----------------------+-----------+----------+-----------+------------
>                        | Ing.      | Taborsky | Michal    |
>                        | Ing.      | Barta    | David     |
>  Novak, Josef          |           | Novak    | Josef     |
>  Saroch, Adrian Walter |           | Saroch   | Adrian    | Walter
> (4 rows)
> 
> Is that a bug or am I missing something ?
> 

Try this:
SELECT (surname || ', ' || firstname || ' ' || secondname) as fullname,  title_pre, surname, firstname, secondname IS
NULLFROM person;
 

You'll find that when secondname is null, so is fullname. Instead of 
your original query, do (untested):

SELECT (surname || ', ' || firstname || ' ' || COALESCE(secondname, '')) as fullname, title_pre, surname, firstname,
secondnameFROM person;
 


HTH,

Joe



pgsql-sql by date:

Previous
From: Tomasz Myrta
Date:
Subject: Re: Concatenating not working properly
Next
From: Dennis Gearon
Date:
Subject: Re: [GENERAL] Yet Another (Simple) Case of Index not used