Mercurial > hg > orthanc-databases
changeset 596:28c9b3e5b3ad find-refactoring
fix
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Wed, 27 Nov 2024 08:52:45 +0100 |
parents | 272eeb046a88 |
children | 0963afafaa07 |
files | PostgreSQL/Plugins/SQL/PrepareIndex.sql |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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();