Re: [SQL] WHERE clause? - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] WHERE clause?
Date
Msg-id 25399.931960802@sss.pgh.pa.us
Whole thread Raw
In response to WHERE clause?  (Jim Rowan <jmr@computing.com>)
List pgsql-sql
Jim Rowan <jmr@computing.com> writes:
>     WHERE (new.host != old.host) or 
>     (old.host IS NOT NULL and new.host IS NULL) or
>         (old.host IS NULL and new.host IS NOT NULL);

> Is this the best way to code the WHERE?  What I'm really after is "did the
> value change?".  I found that the tests to see if one-but-not-both of the
> values is NULL are required to identify times when the value changed to or
> from NULL.  

Yes, because any ordinary operator applied to NULL will produce NULL,
which WHERE interprets as FALSE.  The only operations that actually
work on nulls are IS NULL/IS NOT NULL.  In 6.5 you can use COALESCE
as a handy abbreviation for certain sorts of IS NOT NULL tests, but
offhand I don't see a good way to apply it here.
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] SQL query to check size of database
Next
From: Jérome Knöbl
Date:
Subject: Prolem wiht long query?