Created
August 18, 2013 00:48
-
-
Save ianthrive/6259390 to your computer and use it in GitHub Desktop.
Automatically updated a timestamp column using a trigger in PostgreSQL.
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 updated() | |
RETURNS TRIGGER AS $$ | |
BEGIN | |
NEW.updated = NOW(); | |
RETURN NEW; | |
END; | |
$$ LANGUAGE 'plpgsql'; | |
CREATE TRIGGER updated BEFORE UPDATE ON projects FOR EACH ROW EXECUTE PROCEDURE updated(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment