pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim Rowan <jmr@computing.com>
To: pgsql-sql@hub.org
Subject: WHERE clause?
Date: Wed, 14 Jul 1999 00:17:12 -0500
Message-ID: <199907140517.AAA23407@zee.computing.com> (raw)
In-Reply-To: <199907140300.XAA36099@hub.org>


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@computing.com                                            (512) 374-1143



view thread (10+ messages)  latest in thread

Message-ID: <199907140517.AAA23407@zee.computing.com>
Permalink:  ../199907140517.AAA23407@zee.computing.com/
Also on:    postgresql.org/message-id/199907140517.AAA23407@zee.computing.com

 · 

reply

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-sql@postgresql.org
  Cc: jmr@computing.com, pgsql-sql@hub.org
  Subject: Re: WHERE clause?
  In-Reply-To: <199907140517.AAA23407@zee.computing.com>

* 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