Re: Checking inequality

From: Vitaly Belman <vitalyb(at)gmail(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Checking inequality
Date: 2004-12-11 16:35:57
Message-ID: fa96e3c604121108355d9f6632@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

COALESCE is good enough for me. Thanks.

On Sat, 11 Dec 2004 09:33:32 -0700, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
> On Sat, Dec 11, 2004 at 02:42:21PM +0200, Vitaly Belman wrote:
>
> > IF old.series_id<>new.series_id THEN
> > ...
> > The problem is that series_id can change to be NULL in which case I
> > have problems as "NULL <> 7" doesn't return "true".
> >
> > What can I do to check inequality even in the case that old or new
> > series_id is NULL? I'd prefer not to do zillion silly comparisons
> > (like "IS NULL and IS NOT NULL"). Is there an easy way?
>
> You could COALESCE the fields to a value that would normally be
> invalid:
>
> IF COALESCE(old.series_id, -1) <> COALESCE(new.series_id, -1) THEN
>
> This assumes that you'd want two NULLs to compare as equal.
>
> You could also use CREATE OPERATOR to create an operator that
> behaves as you'd like. This has been discussed recently; see
> the list archives.
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/
>

--
ICQ: 1912453
AIM: VitalyB1984
MSN: tmdagent(at)hotmail(dot)com
Yahoo!: VitalyBe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Wes 2004-12-11 16:44:59 Re: Ridiculous load
Previous Message Michael Fuhr 2004-12-11 16:33:32 Re: Checking inequality