Skip to content

Instantly share code, notes, and snippets.

@ianthrive
Created August 18, 2013 00:48
Show Gist options
  • Save ianthrive/6259390 to your computer and use it in GitHub Desktop.
Save ianthrive/6259390 to your computer and use it in GitHub Desktop.
Automatically updated a timestamp column using a trigger in PostgreSQL.
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