Thread: should this be a trigger or a rule?

should this be a trigger or a rule?

From
marc@oscar.eng.cv.net (Marc Spitzer)
Date:
I have 3 tables: pings, curr_state, ping_log and here is what I want
to happen:
when I insert a row into pings it checks to see if the ping was
sucessful or not.  Then it checks the current state of the interface
in curr_state table and if they match insert the row.  If they do not
match then update curr_state and insert a row into ping_log.  

I am not askng anybody to write it for me, I just want to know what is
the prefered PG method to do this.  Here is my table defs:
drop table pings;

create table pings (
cm_mac macaddr,
ts timestamp,
ping1 int4,
ping2 int4
primary key (cm_mac, ts) );

drop table curr_state ;

create table curr_state (
cm_mac macaddr primary key,
last_change,
up boolean
);

drop table ping_log ;

create table ping_log (
cm_mac macaddr,
ts timestamp,
state boolean,
primary key (cm_mac, ts)
);

Thanks 

marc


Re: should this be a trigger or a rule?

From
Tom Lane
Date:
marc@oscar.eng.cv.net (Marc Spitzer) writes:
> I have 3 tables: pings, curr_state, ping_log and here is what I want
> to happen:
> when I insert a row into pings it checks to see if the ping was
> sucessful or not.

Anything that's most naturally described as driven by insert (or update
or delete) of individual rows is best done as a trigger, IMHO.
        regards, tom lane


Re: should this be a trigger or a rule?

From
Marc Spitzer
Date:
On Sat, Dec 15, 2001 at 09:04:20PM -0500, Tom Lane wrote:
> marc@oscar.eng.cv.net (Marc Spitzer) writes:
> > I have 3 tables: pings, curr_state, ping_log and here is what I want
> > to happen:
> > when I insert a row into pings it checks to see if the ping was
> > sucessful or not.
> 
> Anything that's most naturally described as driven by insert (or update
> or delete) of individual rows is best done as a trigger, IMHO.
> 
>             regards, tom lane


Thanks,

One last question, I am using Xemacs to auto format the code 
for me, I have discovered the sql-postgres but that is only 
in the postgres(psql) window not in the where I edit my code 
window.  I get this in lisp by using  M-x load-library then ilisp
ams perl,tcl, C take care of them selves.

Thanks again,

marc