Re: Testing for null record in plpgsql - Mailing list pgsql-sql

From Craig Ringer
Subject Re: Testing for null record in plpgsql
Date
Msg-id 47FF1605.8050301@postnewspapers.com.au
Whole thread Raw
In response to Testing for null record in plpgsql  (Erik Jones <erik@myemma.com>)
Responses Re: Testing for null record in plpgsql
List 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


pgsql-sql by date:

Previous
From: Erik Jones
Date:
Subject: Testing for null record in plpgsql
Next
From: "Pavel Stehule"
Date:
Subject: Re: Testing for null record in plpgsql