Re: Concatenating not working properly

From: Joe Conway <mail(at)joeconway(dot)com>
To: Michal Taborsky <M(dot)Taborsky(at)sh(dot)cvut(dot)cz>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Concatenating not working properly
Date: 2003-04-09 15:18:07
Message-ID: 3E9439AF.9090505@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 NULL FROM 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, secondname FROM person;

HTH,

Joe

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-04-09 16:18:45 Re: [SQL] Yet Another (Simple) Case of Index not used
Previous Message Tomasz Myrta 2003-04-09 15:17:48 Re: Concatenating not working properly