Created
May 13, 2014 15:57
-
-
Save ianthrive/60965dca49d9f0208822 to your computer and use it in GitHub Desktop.
A PostgreSQL trigger function to updated a timestamp column whenever a row is updated.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION trigger_updated RETURNS TRIGGER LANGUAGE plpgsql AS $$ | |
BEGIN | |
NEW.updated = NOW(); | |
RETURN NEW; | |
END; | |
$$ | |
CREATE TRIGGER updated BEFORE UPDATE ON payment | |
OR EACH ROW WHEN (OLD.* IS DISTINCT FROM NEW.*) | |
EXECUTE PROCEDURE trigger_updated(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment