Skip to content

Instantly share code, notes, and snippets.

@longkey1
Last active October 3, 2015 02:28
Show Gist options
  • Save longkey1/2372566 to your computer and use it in GitHub Desktop.
Save longkey1/2372566 to your computer and use it in GitHub Desktop.
The function for making it move to a deleted table.
CREATE OR REPLACE FUNCTION process_deleted() RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
EXECUTE 'INSERT INTO deleted_' || TG_RELNAME || ' VALUES(($1).*)' USING OLD;
RETURN OLD;
END IF;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment