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 458733A4B3F for ; Fri, 19 Nov 2004 17:48:55 +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 94392-05 for ; Fri, 19 Nov 2004 17:48:45 +0000 (GMT) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id 118C73A4A78 for ; Fri, 19 Nov 2004 17:48:45 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 4.42) id 1CVCsF-000NS7-DN; Fri, 19 Nov 2004 17:48:44 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 0EA3C178FE; Fri, 19 Nov 2004 17:48:36 +0000 (GMT) Message-ID: <419E31F2.4060104@archonet.com> Date: Fri, 19 Nov 2004 17:48:34 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.9 (X11/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Don Drake Cc: pgsql-sql@postgresql.org Subject: Re: NULLS and string concatenation References: <6c21003b0411190912630d4afe@mail.gmail.com> In-Reply-To: <6c21003b0411190912630d4afe@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/202 X-Sequence-Number: 19521 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