[SQL] Statement Triggers and access to other rows in the transaction

2006-11-01 Thread Craig Servin
I have tables representing a ledger system and the accounts on which it operates. I want to do 2 things to all transactions altering the ledger tables. First, all of the inserts into the ledger tables should be balanced ( They should sum to 0 ). If not I want to abort the transaction. Second,

Re: [SQL] Trigger efficiency

2006-02-06 Thread Craig Servin
I do not know of a way to make your trigger run less often, but you could only have it do the insert if something changes. This is what we do: CREATE or replace FUNCTION UPDATE_SERVER_HST() RETURNS TRIGGER AS ' begin if (OLD.ADD_DATE is distinct from NEW.ADD_DATE or OLD.HOSTNAME

[SQL] Updateing pg_trigger and pg_constraint

2005-08-18 Thread Craig Servin
I am trying to make some foreign keys deferrable and initially deferred. These foreign key constraints already exist so I was going to change them by updating pg_trigger and pg_constraint. However the changes do not seem to take affect. Is there something I need to do to get PostgreSQL to rec

[SQL] NEW and OLD as ROWS

2005-08-03 Thread Craig Servin
I am writing an update trigger that I want to fire when any field changes. It looks like two ROWS can be compared very easily, but not the two RECORDS OLD and NEW. Is there a way to do: NEW IS DISTINCT FROM OLD in a trigger? This would help me not have to write a specific trigger for each ta