Re: Is this a feature ?

From: James Orr <james(at)orrwhat(dot)net>
To: David BOURIAUD <david(dot)bouriaud(at)ac-rouen(dot)fr>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Is this a feature ?
Date: 2002-06-04 15:14:36
Message-ID: 200206041114.36984.james@orrwhat.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tuesday 04 June 2002 04:18, David BOURIAUD wrote:
> Hi the list !
> I've read the docs, and found that you could concatenate two or more
> strings in one select statement like this :
> select
> civ || name || forname as identity
> from
> person;
>
> This just works fine and returns rows with only one column named identity.
> So far, if one of the fields (civ, name or forname) is null, identity is
> null... That doesn't seems right, since it means that 1+2+0 = 0 !!!!
> Has anybody else seen the same strange behaviour ? And is there a way to
> work this around ?
> Please, don't answer me to use the function textcat (text, text), since it
> behaves the same and makes queries quite unreadeable...
> eg.
> select
> textcat ( textcat (civ, name), forname) as identity
> from person;
> is quite readeable, but when you add fields separator, it isn't.

NULL != 0. 1+2+NULL=NULL.

Try ...
CASE WHEN civ IS NOT NULL THEN civ ELSE '' END ||
CASE WHEN name IS NOT NULL THEN name ELSE '' END ||
CASE WHEN forname IS NOT NULL THEN forname ELSE '' END AS identity

- James

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joel Burton 2002-06-04 17:26:32 Re: Is this a feature ?
Previous Message David BOURIAUD 2002-06-04 14:55:39 Re: Is this a feature ?