From: Craig Ringer <ringerc@ringerc.id.au>
To: Laszlo Nagy <gandalf@shopzeus.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: need help to write a function in postgresql
Date: Fri, 03 Aug 2012 16:48:30 +0800
Message-ID: <501B905E.1050706@ringerc.id.au> (raw)
In-Reply-To: <501B8DB7.5050700@shopzeus.com>
References: <000b01cd658e$e66ae920$b340bb60$@avineonindia.com>
<ju8nfr$aco$1@dough.gmane.org>
<501B8DB7.5050700@shopzeus.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: ringerc@ringerc.id.au, gandalf@shopzeus.com
Subject: Re: need help to write a function in postgresql
In-Reply-To: <501B905E.1050706@ringerc.id.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox