I have the following schema setup in PG 8.4 SQLFiddle
The idea is to write a generic function so that when ever the article relation is updated or the workshop relation is updated then the modified date is set to the current date.
I have this building fine but the functoion does not appear to actually update the date when ut should. This question looked interesting but it was not a generaly purpose function: Accepted answer.
What should I be doing to get thsi working?
You've used AFTER
triggers for update value in NEW row. Try BEFORE
triggers:
-- Articles table
CREATE TRIGGER update_articles_modified_date_to_now BEFORE UPDATE
ON articles FOR EACH ROW EXECUTE PROCEDURE
update_modified_date_to_now();
-- Workshop table
CREATE TRIGGER update_workshop_modified_date_to_now BEFORE UPDATE
ON workshop FOR EACH ROW EXECUTE PROCEDURE
update_modified_date_to_now();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.