From: Joe Conway <mail@joeconway.com>
To: Michal Taborsky <M.Taborsky@sh.cvut.cz>
Cc: pgsql-sql@postgresql.org
Subject: Re: Concatenating not working properly
Date: Wed, 09 Apr 2003 08:18:07 -0700
Message-ID: <3E9439AF.9090505@joeconway.com> (raw)
In-Reply-To: <3E94343A.1060108@sh.cvut.cz>
References: <3E94343A.1060108@sh.cvut.cz>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mail@joeconway.com, M.Taborsky@sh.cvut.cz
Subject: Re: Concatenating not working properly
In-Reply-To: <3E9439AF.9090505@joeconway.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox