pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedConcatenating does not work properly
2+ messages / 2 participants
[nested] [flat]
* Concatenating does not work properly
@ 2003-04-09 14:14 Michal Taborsky <M.Taborsky@sh.cvut.cz>
0 siblings, 1 reply; 2+ messages in thread
From: Michal Taborsky @ 2003-04-09 14:14 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Concatenating does not work properly
@ 2003-04-10 01:00 Lee Harr <missive@frontiernet.net>
parent: Michal Taborsky <M.Taborsky@sh.cvut.cz>
0 siblings, 0 replies; 2+ messages in thread
From: Lee Harr @ 2003-04-10 01:00 UTC (permalink / raw)
To: pgsql-sql
In article <b719sp$24ki$1@news.hub.org>, Michal Taborsky wrote:
> 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 ?
>
I bet that one of surname, firstname, or secondname is NULL
in those rows where fullname is blank.
You might try:
SELECT (coalesce(surname, '') || ', ' ||
coalesce(firstname, '') || ' ' ||
coalesce(secondname, '')) as fullname
FROM person;
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-04-10 01:00 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-04-09 14:14 Concatenating does not work properly Michal Taborsky <M.Taborsky@sh.cvut.cz>
2003-04-10 01:00 ` Lee Harr <missive@frontiernet.net>
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