From 987940f1fcaf65d25f56b6d551bd36326cf9137b Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Fri, 5 Jun 2026 20:42:51 +0000 Subject: [PATCH] EVENTS with Behavior = sdb_other_species cannot be related to ROLES row --- db/schemas/lib/triggers/create/roles.m4 | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/db/schemas/lib/triggers/create/roles.m4 b/db/schemas/lib/triggers/create/roles.m4 index aaae935..4d757b0 100644 --- a/db/schemas/lib/triggers/create/roles.m4 +++ b/db/schemas/lib/triggers/create/roles.m4 @@ -71,6 +71,49 @@ CREATE OR REPLACE FUNCTION roles_func () FROM events WHERE events.eid = NEW.eid; END IF; + + -- The event may not be a sdb_other_species type of event + IF TG_OP = 'INSERT' + AND a_behavior = 'sdb_other_species' THEN + DECLARE + a_focal follows.focal%TYPE; + a_date follows.date%TYPE; + + BEGIN + SELECT follows.focal, follows.date + INTO a_focal , a_date + FROM follows + WHERE follows.fid = a_fid; + IF FOUND THEN + RAISE EXCEPTION integrity_constraint_violation USING + MESSAGE = 'Error on ' || TG_OP || ' of ROLES' + , DETAIL = 'An event with a (Behavior) = (sdb_other_species)' + || ' cannot be related to a chimpanzee; cannot' + || ' have a related ROLES row' + || ': Key (PID) = (' + || NEW.pid + || '), Value (EID) = (' + || NEW.eid + || '), Value (Role) = (' + || NEW.role + || '), Value (Participant) = (' + || NEW.participant + || '): Value (EVENTS.Behavior) = (' + || a_behavior + || '), Value (EVENTS.Start) = (' + || a_start + || '), Value (EVENTS.Stop) = (' + || a_stop + || '): Key (FOLLOWS.FID) = (' + || a_fid + || '), Value (FOLLOWS.Focal) = (' + || a_focal + || '), Value (FOLLOWS.Date) = (' + || a_date + || ')'; + END IF; + END; + END IF; -- The participant must be under study at the time of the follow. IF TG_OP = 'INSERT' THEN -- 2.34.1