WHERE clause? - Mailing list pgsql-sql

From Jim Rowan
Subject WHERE clause?
Date
Msg-id 199907140517.AAA23407@zee.computing.com
Whole thread Raw
Responses Re: [SQL] WHERE clause?
Re: [SQL] WHERE clause?
List pgsql-sql
I'm trying to create a log table to track changes to a table..  so I've
created a set of rules that look something like this:

CREATE RULE "m_log_change" AS ON UPDATE TO "machine"
do ( INSERT INTO machine_log (who, date, machnum, col, newval)   SELECT getpgusername(), 'now'::text, old.machnum,
'host',new.host   WHERE (new.host != old.host) or (old.host IS NOT NULL and new.host IS NULL) or    (old.host IS NULL
andnew.host IS NOT NULL);
 
... more similar INSERT statements with different WHERE clauses..
);

My question is:

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.  

Seems like a lot of extra work...


Jim Rowan            DCSI            DCE/DFS/Sysadmin Consulting
jmr@computing.com                                            (512) 374-1143


pgsql-sql by date:

Previous
From: Michael Richards
Date:
Subject: counting bools in a complex query
Next
From: Johann Spies
Date:
Subject: OFF-TOPIC: Postgresql for NT?