Skip to content

Instantly share code, notes, and snippets.

@froop
Last active May 5, 2022 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save froop/f13a443a129527132e33649347e02158 to your computer and use it in GitHub Desktop.
Save froop/f13a443a129527132e33649347e02158 to your computer and use it in GitHub Desktop.
[PostgreSQL] trigger sample
-- psql -p 24001 -U hinemos -f create-trigger-sample.sql
CREATE OR REPLACE FUNCTION log_cc_cfg_facility_relation_delete() RETURNS TRIGGER AS $$
BEGIN
RAISE LOG 'DELETE cc_cfg_facility_relation: % %',
OLD.parent_facility_id, OLD.child_facility_id;
RETURN NULL;
END
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_cc_cfg_facility_relation_delete
AFTER DELETE ON setting.cc_cfg_facility_relation
FOR EACH ROW
EXECUTE PROCEDURE log_cc_cfg_facility_relation_delete();
-- psql -p 24001 -U hinemos -f drop-trigger-sample.sql
DROP TRIGGER IF EXISTS trg_cc_cfg_facility_relation_delete
ON setting.cc_cfg_facility_relation;
DROP FUNCTION IF EXISTS log_cc_cfg_facility_relation_delete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment