chrissharp123

Untitled

Oct 20th, 2025
1,461
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DECLARE
  2.      new_copy_location INT;
  3.  BEGIN
  4.      IF (TG_OP = 'UPDATE') THEN
  5.          IF NEW.location = OLD.location AND NEW.call_number = OLD.call_number AND NEW.circ_lib = OLD.circ_lib THEN
  6.              RETURN NEW;
  7.          END IF;
  8.      END IF;
  9.      SELECT INTO new_copy_location acpl.id FROM asset.copy_location acpl JOIN actor.org_unit_ancestors_distance((SELECT owning_lib FROM asset.call_number WHERE id = NEW.call_number)) aouad ON acpl.owning_lib = aouad.id WHERE deleted IS FALSE AND name = (SELECT name FROM asset.copy_location WHERE id = NEW.location) ORDER BY distance LIMIT 1;
  10.      IF new_copy_location IS NULL THEN
  11.          SELECT INTO new_copy_location acpl.id FROM asset.copy_location acpl JOIN actor.org_unit_ancestors_distance(NEW.circ_lib) aouad ON acpl.owning_lib = aouad.id WHERE deleted IS FALSE AND name = (SELECT name FROM asset.copy_location WHERE id = NEW.location) ORDER BY distance LIMIT 1;
  12.      END IF;
  13.      IF new_copy_location IS NOT NULL THEN
  14.          NEW.location = new_copy_location;
  15.      END IF;
  16.      RETURN NEW;
  17.  END;  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment