Re: Concatenating not working properly

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
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:17:48
Message-ID: 3E94399C.9080009@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joe Conway 2003-04-09 15:18:07 Re: Concatenating not working properly
Previous Message Tom Lane 2003-04-09 15:12:48 Re: question about visibilty while updating multiple rows .