pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Post Gres triggers for trail
2+ messages / 2 participants
[nested] [flat]

* Post Gres triggers for trail
@ 2005-04-25 14:35 Mandar M Bhosale <mbhosale@cybage.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Mandar M Bhosale @ 2005-04-25 14:35 UTC (permalink / raw)
  To: pgsql-admin

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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Post Gres triggers for trail
@ 2005-05-02 12:41 Jason Minion <jason.minion@sigler.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jason Minion @ 2005-05-02 12:41 UTC (permalink / raw)
  To: 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();
 
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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-05-02 12:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-25 14:35 Post Gres triggers for trail Mandar M Bhosale <mbhosale@cybage.com>
2005-05-02 12:41 Re: Post Gres triggers for trail Jason Minion <jason.minion@sigler.com>

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