Skip site navigation (1) Skip section navigation (2)

Re: Testing for null record in plpgsql

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Erik Jones <erik(at)myemma(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org List" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Testing for null record in plpgsql
Date: 2008-04-11 07:40:53
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
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

In response to


pgsql-sql by date

Next:From: Erik JonesDate: 2008-04-11 14:35:28
Subject: Re: Testing for null record in plpgsql
Previous:From: Pavel StehuleDate: 2008-04-11 05:21:58
Subject: Re: Testing for null record in plpgsql

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group