Re: need help to write a function in postgresql

From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Laszlo Nagy <gandalf(at)shopzeus(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: need help to write a function in postgresql
Date: 2012-08-03 08:48:30
Message-ID: 501B905E.1050706@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 08/03/2012 04:37 PM, Laszlo Nagy wrote:
> It is also better because with a view, you can also do " name is null
> ". But you cannot do that with a function (unless you write
> unnecessary circumstancial code.)
>
While I agree with you on the view - among other things, it lets the
query optimiser push conditions down into the view query - there is a
reasonable answer to the problem of comparing to NULL. Just use IS
DISTINCT FROM, eg:

WHERE name IS DISTINCT FROM _test_variable

"IS DISTINCT FROM" is an equality comparison that treats null as a
comparable value like any other, so "NULL IS DISTINCT FROM NULL" is
false. Very handy.

--
Craig Ringer

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message JC de Villa 2012-08-03 08:58:28 Re: Messed up time zones
Previous Message Laszlo Nagy 2012-08-03 08:37:11 Re: need help to write a function in postgresql