Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do $$
- declare
- r_audit record;
- r_pack record;
- v_company_to_keep integer;
- begin
- select id into v_company_to_keep from company where trading_name ilike 'ROCHE';
- for r_audit in select id from audit where company_id <> v_company_to_keep
- loop
- raise notice 'Audit id %', r_audit.id;
- delete from bill_item_audit where audit_id = r_audit.id;
- delete from audit_contract_service where audit_id = r_audit.id;
- --delete from audit_marketing_discount where audit_id = r_audit.id;
- for r_pack in select * from audit_package where audit_id = r_audit.id
- loop
- raise notice 'Package id %', r_audit.id;
- delete from audit_package_item where audit_package_id = r_pack.id;
- end loop;
- delete from audit_package where audit_id = r_audit.id;
- delete from audit where id = r_audit.id;
- end loop;
- end $$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement