Re: NULLS and string concatenation - Mailing list pgsql-sql

From Richard Huxton
Subject Re: NULLS and string concatenation
Date
Msg-id 419E31F2.4060104@archonet.com
Whole thread Raw
In response to NULLS and string concatenation  (Don Drake <dondrake@gmail.com>)
Responses Re: NULLS and string concatenation
List 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


pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: NULLS and string concatenation
Next
From: Michael Fuhr
Date:
Subject: Re: NULLS and string concatenation