# HG changeset patch # User Alain Mazy # Date 1732693965 -3600 # Node ID 28c9b3e5b3ad9dba002becb0825c4948b3f3dd03 # Parent 272eeb046a881f139e2e9ce6883525ce529b5e63 fix diff -r 272eeb046a88 -r 28c9b3e5b3ad PostgreSQL/Plugins/SQL/PrepareIndex.sql --- a/PostgreSQL/Plugins/SQL/PrepareIndex.sql Tue Nov 26 17:59:14 2024 +0100 +++ b/PostgreSQL/Plugins/SQL/PrepareIndex.sql Wed Nov 27 08:52:45 2024 +0100 @@ -630,11 +630,11 @@ parent_id BIGINT; BEGIN IF TG_OP = 'INSERT' THEN - IF NEW.parentId IS NOT NULL THEN + IF new.parentId IS NOT NULL THEN -- try to increment the childcount from the parent UPDATE ChildCount SET childCount = childCount + 1 - WHERE parentId = NEW.parentId + WHERE parentId = new.parentId RETURNING parentId INTO parent_id; -- this should only happen for old studies whose childCount has not yet been computed @@ -648,19 +648,19 @@ END IF; -- this is a future parent, start counting the children - IF NEW.resourcetype < 3 THEN + IF new.resourcetype < 3 THEN insert into ChildCount (parentId, childCount) values (new.internalId, 0); END IF; ELSIF TG_OP = 'DELETE' THEN - IF NEW.parentId IS NOT NULL THEN + IF old.parentId IS NOT NULL THEN -- Decrement the child count for the parent UPDATE ChildCount SET childCount = childCount - 1 - WHERE parentId = OLD.parentId + WHERE parentId = old.parentId RETURNING parentId INTO parent_id; -- this should only happen for old studies whose childCount has not yet been computed @@ -682,14 +682,14 @@ CREATE TRIGGER IncrementChildCount AFTER INSERT ON Resources FOR EACH ROW -EXECUTE FUNCTION UpdateChildCount(); +EXECUTE PROCEDURE UpdateChildCount(); -- Trigger for DELETE CREATE TRIGGER DecrementChildCount AFTER DELETE ON Resources FOR EACH ROW WHEN (OLD.parentId IS NOT NULL) -EXECUTE FUNCTION UpdateChildCount(); +EXECUTE PROCEDURE UpdateChildCount();