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

Re: NULLS and string concatenation

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: Richard Huxton <dev(at)archonet(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: NULLS and string concatenation
Date: 2004-11-19 19:04:18
Message-ID: 20041119105650.E40388@megazone.bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-sql
On Fri, 19 Nov 2004, Don Drake wrote:

> On Fri, 19 Nov 2004 17:48:34 +0000, Richard Huxton <dev(at)archonet(dot)com> wrote:
> > 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'm using NULL to mean no value.  Logically, NULL is unknown, I agree.
>
> I'm trying to dynamically create an INSERT statement in a function
> that sometimes receives NULL values.
>
> This is still strange to me.  In Oracle, the same query would not
> replace the *entire* string with a NULL, it treats the NULL as a no
> value.

Oracle has some incompatibilities with the SQL spec (at least 92/99) wrt
NULLs and empty strings so it isn't a good comparison point. The spec is
pretty clear that if either argument to concatenation is NULL the output
is NULL.

> I can't find in the documentation where string concatenation of any
> string and NULL is NULL.

I'm not sure it does actually.  I'd have expected to see some general text
on how most operators return NULL for NULL input but a quick scan didn't
find any.


In response to

Responses

pgsql-sql by date

Next:From: Mischa SandbergDate: 2004-11-19 19:23:43
Subject: Re: SQL Question
Previous:From: Don DrakeDate: 2004-11-19 18:40:02
Subject: Re: NULLS and string concatenation

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