1

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?

2
  • 1
    Please include the relevant part of your code in your question and don't link to an external site. Commented Aug 22, 2013 at 13:50
  • @Hyposaurus check my answer. Is it what you want or do you need more help? Commented Aug 24, 2013 at 16:13

1 Answer 1

1

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();

sql fiddle demo

Sign up to request clarification or add additional context in comments.

1 Comment

Great this is the thing! Thanks for the help ((I went on holidays so that's the delay there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.