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 7063840C18A for ; Sun, 30 Jan 2005 19:43:22 +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 86265-08 for ; Sun, 30 Jan 2005 19:43:10 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.194]) by svr1.postgresql.org (Postfix) with ESMTP id 72C9540C0B5 for ; Sun, 30 Jan 2005 19:41:29 +0000 (GMT) Received: by wproxy.gmail.com with SMTP id 67so485652wri for ; Sun, 30 Jan 2005 11:41:28 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=L80rx7gksNsp7I7jS74wR2WevJ7IeecHQBxudw6RiCcltRHFh5px+rNWJEPNH6nEABesHGlpNLnY9Igpkv/K1cDs/YWcP+9KJfdtpCVnazquHen20+J+O/Xw8nQUOaS3QkLSCXM9Hy7ncArpL0fLQtaOgsWCuzLIXskuX+23bIY= Received: by 10.54.46.67 with SMTP id t67mr172593wrt; Sun, 30 Jan 2005 11:41:28 -0800 (PST) Received: by 10.54.4.71 with HTTP; Sun, 30 Jan 2005 11:41:28 -0800 (PST) Message-ID: <6c21003b0501301141234c256b@mail.gmail.com> Date: Sun, 30 Jan 2005 13:41:28 -0600 From: Don Drake Reply-To: Don Drake To: pgsql-sql@postgresql.org Subject: plpgsql functions and NULLs Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200501/313 X-Sequence-Number: 20101 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; IF FOUND ... Is there a way to do the lookup in one statement?? This could get ugly quick. I'm using v7.4. Thanks. -Don -- Donald Drake President Drake Consulting http://www.drakeconsult.com/ 312-560-1574