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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2004-11-19 17:53:33 Re: NULLS and string concatenation
Previous Message Bruno Wolff III 2004-11-19 17:45:43 Re: NULLS and string concatenation