Обсуждение: Post Gres triggers for trail

Поиск
Список
Период
Сортировка

Post Gres triggers for trail

От
"Mandar M Bhosale"
Дата:
I have difficulty in setting a trigger to have trail of my project
 
I need to update the modified_date of my database tables through trigger as
 
CREATE 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

Re: Post Gres triggers for trail

От
"Jason Minion"
Дата:
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();
 
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;
 
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 trail

I have difficulty in setting a trigger to have trail of my project
 
I need to update the modified_date of my database tables through trigger as
 
CREATE 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