Re: Post Gres triggers for trail
От | Jason Minion |
---|---|
Тема | Re: Post Gres triggers for trail |
Дата | |
Msg-id | 0105A1BF505D304E9E5AF38B63E40E4E807A25@exchange.siglercompanies.com обсуждение исходный текст |
Ответ на | Post Gres triggers for trail ("Mandar M Bhosale" <mbhosale@cybage.com>) |
Список | pgsql-admin |
You probably want to run the trigger "BEFORE UPDATE" unless you have some other code depending on the value of modified_date during the update, and also instead of "RETURN NULL;" do a "RETURN NEW;". Here's an example from one of my triggers:
Trigger definition:
CREATE TRIGGER trig_rec_returndate
BEFORE UPDATE
ON rec_main
FOR EACH ROW
EXECUTE PROCEDURE fun_rec_returndate();
BEFORE UPDATE
ON rec_main
FOR EACH ROW
EXECUTE PROCEDURE fun_rec_returndate();
Trigger function definition:
CREATE OR REPLACE FUNCTION fun_rec_returndate()
RETURNS "trigger" AS
'BEGIN
IF NEW.returncode IS NOT NULL THEN
IF OLD.returndate IS NULL THEN
NEW.returndate := \'now\';
END IF;
END IF;
RETURN NEW;
END;'
LANGUAGE 'plpgsql' VOLATILE;
RETURNS "trigger" AS
'BEGIN
IF NEW.returncode IS NOT NULL THEN
IF OLD.returndate IS NULL THEN
NEW.returndate := \'now\';
END IF;
END IF;
RETURN NEW;
END;'
LANGUAGE 'plpgsql' VOLATILE;
In that case returndate is a timestamp. Hope it helps!
Jason Minion
-----Original Message-----
From: pgsql-admin-owner@postgresql.org [mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Mandar M Bhosale
Sent: Monday, April 25, 2005 9:36 AM
To: pgsql-admin@postgresql.org
Subject: [ADMIN] Post Gres triggers for trailI have difficulty in setting a trigger to have trail of my projectI need to update the modified_date of my database tables through trigger asCREATE OR REPLACE TRIGGER taril_trigger AFTER UPDATE ON test_trigger FOR EACH ROW
EXECUTE PROCEDURE pro_trail();pro_trail(){
BEGIN
NEW.modified_date=(select current_timestamp)
return NULL;
END;
}
Can anybody help me out!!!Mandar M. Bhosale
В списке pgsql-admin по дате отправления: