WHERE clause?

From: Jim Rowan <jmr(at)computing(dot)com>
To: pgsql-sql(at)hub(dot)org
Subject: WHERE clause?
Date: 1999-07-14 05:17:12
Message-ID: 199907140517.AAA23407@zee.computing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 and new.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(at)computing(dot)com (512) 374-1143

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message webmaster 1999-07-14 08:52:10 Few questions about my slow query
Previous Message Johann Spies 1999-07-14 04:58:05 OFF-TOPIC: Postgresql for NT?