Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 97D652E0085 for ; Fri, 11 Apr 2008 05:44:56 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 70645-04 for ; Fri, 11 Apr 2008 05:44:54 -0300 (ADT) Received: from mx1.hub.org (mx1.hub.org [200.46.208.106]) by developer.postgresql.org (Postfix) with ESMTP id 829BA2E0083 for ; Fri, 11 Apr 2008 05:44:54 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by mx1.hub.org (Postfix) with ESMTP id 608B7B076EE for ; Fri, 11 Apr 2008 05:44:52 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id 692EBD55CC; Fri, 11 Apr 2008 15:41:07 +0800 (WST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 336671E0435; Fri, 11 Apr 2008 15:41:10 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id W-H23Eb+s44K; Fri, 11 Apr 2008 15:41:08 +0800 (WST) Received: from [203.161.97.213] (203.161.97.213.static.amnet.net.au [203.161.97.213]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTP id 898C11E0434; Fri, 11 Apr 2008 15:41:08 +0800 (WST) Message-ID: <47FF1605.8050301@postnewspapers.com.au> Date: Fri, 11 Apr 2008 15:40:53 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Erik Jones Cc: "pgsql-sql@postgresql.org List" Subject: Re: Testing for null record in plpgsql References: <491AB2F3-6ACF-4D58-A195-9D7A848E479A@myemma.com> In-Reply-To: <491AB2F3-6ACF-4D58-A195-9D7A848E479A@myemma.com> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/73 X-Sequence-Number: 30612 Erik Jones wrote: > Now, let's say I want to call this from another function and test the > result to see if I have a null record (null, null),. I've got the > following working but it feels like there should be something much > simpler but I just can't seem to hit on it. Is this it? I'm assuming that returns_null_maybe() is a dummy to show general behavior. I can't imagine why you'd ever want to do what it's doing. In general I'm suspicious of code that's testing for a real, known value and returning NULL in its place. It seems like an odd thing to do. Still, I'm sure you have your reasons and they probably make sense in the real application rather than the simplified example. You can tidy test_null_rec a little by just using: RETURN row(res.*) IS DISTINCT FROM row(null_rec.*); but otherwise, without incorporating it into the containing query as a subquery I don't see much to be done. I'm still curious about the purpose of using null values like this is, though. -- Craig Ringer