Skip to content

Instantly share code, notes, and snippets.

@dongryphon
dongryphon / add.sql
Last active October 24, 2023 16:29
Closure table triggers
-- NOTE: Organizations have id and parentOrgId columns
-- OrgClosure has parentId, childId, depth columns
CREATE OR REPLACE TRIGGER Org_Add_Trigger
AFTER INSERT ON Organization
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
-- must insert in this order...
insert into OrgClosure (parentId, childId, depth)