pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomasz Myrta <jasiek@klaster.net>
To: Michal Taborsky <M.Taborsky@sh.cvut.cz>
Cc: pgsql-sql@postgresql.org
Subject: Re: Concatenating not working properly
Date: Wed, 09 Apr 2003 17:17:48 +0200
Message-ID: <3E94399C.9080009@klaster.net> (raw)
In-Reply-To: <3E94343A.1060108@sh.cvut.cz>
References: <3E94343A.1060108@sh.cvut.cz>

Uz.ytkownik Michal Taborsky napisa?:
> Hello,
> 
> I am facing a problem I cannot really explain to myself. I have a table 
> with personal data which has columns surname, firstname, secondname, 
> title and I want to do a simple select like this:
> 
> SELECT (surname || ', ' || firstname || ' ' || secondname) as fullname 
> FROM person
> 
> For some rows (from what I recognised it is with rows, which have the 
> title column empty) it works, for some it returns empty string:
> 
> 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 ?
> 
> Thanks,
> Michal
It works as it should.

If you want to add null values, use:
SELECT coalesce(surname,'') || ', ' || coalesce(firstname,'') || ' ' || 
coalesce(secondname,'') as fullname
 > FROM person

Remember - NULL value means that value doesn't exist, so you can't add 
"not existence" to other existing values.

Regards,
Tomasz Myrta




view thread (3+ messages)  latest in thread

Message-ID: <3E94399C.9080009@klaster.net>
Permalink:  ../3E94399C.9080009@klaster.net/
Also on:    postgresql.org/message-id/3E94399C.9080009@klaster.net

 · 

reply

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: jasiek@klaster.net, M.Taborsky@sh.cvut.cz
  Subject: Re: Concatenating not working properly
  In-Reply-To: <3E94399C.9080009@klaster.net>

* 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