X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 483623A4C09 for ; Fri, 19 Nov 2004 19:04:32 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20013-05 for ; Fri, 19 Nov 2004 19:04:20 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id EB9FE3A4BE5 for ; Fri, 19 Nov 2004 19:04:20 +0000 (GMT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 45A9D358C8; Fri, 19 Nov 2004 11:04:19 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 2137F358C1; Fri, 19 Nov 2004 11:04:19 -0800 (PST) Date: Fri, 19 Nov 2004 11:04:18 -0800 (PST) From: Stephan Szabo To: Don Drake Cc: Richard Huxton , pgsql-sql@postgresql.org Subject: Re: NULLS and string concatenation In-Reply-To: <6c21003b041119104039c88faf@mail.gmail.com> Message-ID: <20041119105650.E40388@megazone.bigpanda.com> References: <6c21003b0411190912630d4afe@mail.gmail.com> <419E31F2.4060104@archonet.com> <6c21003b041119104039c88faf@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/205 X-Sequence-Number: 19524 On Fri, 19 Nov 2004, Don Drake wrote: > On Fri, 19 Nov 2004 17:48:34 +0000, Richard Huxton 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.