Created
January 22, 2016 03:43
-
-
Save arduanov/db2c4dba99e3bf90f938 to your computer and use it in GitHub Desktop.
psql on update
This file contains hidden or 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
| up vote | |
| 62 | |
| down vote | |
| Create a function that updates the changetimestamp column of a table like so: | |
| CREATE OR REPLACE FUNCTION update_changetimestamp_column() | |
| RETURNS TRIGGER AS $$ | |
| BEGIN | |
| NEW.changetimestamp = now(); | |
| RETURN NEW; | |
| END; | |
| $$ language 'plpgsql'; | |
| Create a trigger on the table that calls the update_changetimestamp_column() function whenever an update occurs like so: | |
| CREATE TRIGGER update_ab_changetimestamp BEFORE UPDATE | |
| ON ab FOR EACH ROW EXECUTE PROCEDURE | |
| update_changetimestamp_column(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment