X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AB8B54762F6 for ; Wed, 9 Apr 2003 21:00:51 -0400 (EDT) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 12DFF476237 for ; Wed, 9 Apr 2003 21:00:51 -0400 (EDT) Received: by news.hub.org (Postfix, from userid 8) id DE90D43A89E; Wed, 9 Apr 2003 21:00:50 -0400 (EDT) From: Lee Harr X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Concatenating does not work properly Date: Thu, 10 Apr 2003 01:00:50 +0000 (UTC) Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 40 Message-ID: References: Reply-To: missive@hotmail.com X-Complaints-To: usenet@news.hub.org User-Agent: slrn/0.9.7.3 (FreeBSD) To: pgsql-sql@postgresql.org X-Spam-Status: No, hits=-29.3 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/180 X-Sequence-Number: 12881 In article , 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;