\set ECHO all
\timing
-SELECT id
-FROM actor.usr WHERE home_ou IN (
- SELECT (actor.org_unit_descendants(id)).id FROM actor.org_unit
- WHERE shortname IN (SELECT shortname FROM esi.ous_to_del)
+BEGIN;
+
+DELETE FROM acq.lineitem WHERE picklist IN (SELECT id FROM acq.picklist WHERE org_unit IN
+ (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del)
);
+DELETE FROM acq.picklist WHERE org_unit IN (SELECT (actor.org_unit_descendants(id)).id from actor.org_unit where shortname = :ou_to_del);
--- find the problems and clear them up
+COMMIT;
\t
\psql format unaligned
-\o 16_delete_usrs_stage_2.sql
+\o 17_delete_usrs_stage_2.sql
SELECT 'ALTER TABLE actor.usr DISABLE RULE protect_user_delete;';
SELECT 'DELETE FROM actor.usr WHERE id = ' || id || ';'