Skip site navigation (1) Skip section navigation (2)

Re: NULLS and string concatenation

From: Richard Huxton <dev(at)archonet(dot)com>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: NULLS and string concatenation
Date: 2004-11-19 17:48:34
Message-ID: 419E31F2.4060104@archonet.com (view raw or flat)
Thread:
Lists: pgsql-sql
Don Drake wrote:
> select 'some text, should be null:'|| NULL
> 
> This returns NULL and no other text.  Why is that?  I wasn't expecting
> the "some text.." to disappear altogether.
> 
> Is this a bug?

No. Null is "unknown" if you append unknown (null) to a piece of text, 
the result is unknown (null) too.

If you're using NULL to mean something other than unknown, you probably 
want to re-examine your reasons why.

> I was able to work around the problem by using COALESCE (and casting
> variables since it wants the same data types passed to it).

That's the correct procedure (although ask yourself if you should have 
nulls rather than just empty strings).

-- 
   Richard Huxton
   Archonet Ltd

In response to

Responses

pgsql-sql by date

Next:From: Michael FuhrDate: 2004-11-19 17:53:33
Subject: Re: NULLS and string concatenation
Previous:From: Bruno Wolff IIIDate: 2004-11-19 17:45:43
Subject: Re: NULLS and string concatenation

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group