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 CCF288BA119 for ; Mon, 31 Jan 2005 21:33:03 +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 59677-09 for ; Mon, 31 Jan 2005 21:32:57 +0000 (GMT) Received: from megazone.bigpanda.com (unknown [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id E451E8BA109 for ; Mon, 31 Jan 2005 21:32:55 +0000 (GMT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id C84F735605; Mon, 31 Jan 2005 13:31:34 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id A2E3835592; Mon, 31 Jan 2005 13:31:34 -0800 (PST) Date: Mon, 31 Jan 2005 13:31:34 -0800 (PST) From: Stephan Szabo To: Don Drake Cc: pgsql-sql@postgresql.org Subject: Re: plpgsql functions and NULLs In-Reply-To: <6c21003b0501301141234c256b@mail.gmail.com> Message-ID: <20050131132701.G12960@megazone.bigpanda.com> References: <6c21003b0501301141234c256b@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.009 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/317 X-Sequence-Number: 20105 On Sun, 30 Jan 2005, Don Drake wrote: > OK, I have a function that finds records that changed in a set of > tables and attempts to insert them into a data warehouse. > > There's a large outer loop of candidate rows and I inspect them to see > if the values really changed before inserting. > > My problem is that when I look to see if the row exists in the > warehouse already, based on some IDs, it fails when an ID is NULL. > The ID is nullable, so that's not a problem. > > But I'm forced to write an IF statement looking for the potential NULL > and write 2 queries: > > IF omcr_id is null > select * from .... > WHERE omcr_id is NULL > AND ... > ELSE > select * from .... > WHERE omcr_id=candidate.omcr_id > AND .... > END IF; Hmm, perhaps some form like: WHERE not(candidate.omcr_id is distinct from omcr_id)