Also simplify the WHERE clause in the UPDATE statement, making its intentions clearer to my eye at least
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
UPDATE action.hold_request
SET selection_ou = request_lib
-WHERE id IN (
- SELECT ahr.id FROM action.hold_request ahr
- LEFT JOIN actor.org_unit aou ON aou.id = ahr.selection_ou
- WHERE aou.id IS NULL
+WHERE selection_ou NOT IN (
+ SELECT id FROM actor.org_unit
);
-ALTER TABLE action.hold_request ADD CONSTRAINT hold_request_selection_ou_fkey FOREIGN KEY (selection_ou) REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED;
+ALTER TABLE action.hold_request ADD CONSTRAINT hold_request_selection_ou_fkey FOREIGN KEY (selection_ou) REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED NOT VALID;
+ALTER TABLE action.hold_request VALIDATE CONSTRAINT hold_request_selection_ou_fkey;
COMMIT;