chrissharp123

Untitled

Oct 11th, 2018
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Period used to determine how long call numbers and bibs without
  2. -- copies stick around in the nontranscendental sources.
  3. \set period '''30 days'''::INTERVAL
  4.  
  5. -- CALL NUMBERS SANS COPIES/URIS
  6. WITH empty_acn AS (
  7. SELECT DISTINCT acn.id
  8. FROM asset.call_number acn
  9. LEFT JOIN asset.copy acp ON acp.call_number = acn.id AND NOT acp.deleted
  10. LEFT JOIN asset.uri_call_number_map aucnm ON aucnm.call_number = acn.id
  11. WHERE acn.id > 0 AND acp IS NULL AND aucnm IS NULL AND NOT acn.deleted AND acn.create_date < NOW() - :period
  12. )
  13. DELETE FROM asset.call_number
  14. WHERE id IN
  15. (SELECT id
  16.  FROM empty_acn);
  17.  
  18. -- BIBS WITH NO CALL NUMBERS
  19. WITH empty_bib AS (
  20. SELECT DISTINCT bre.id
  21. FROM biblio.record_entry bre
  22. LEFT JOIN asset.call_number acn ON acn.record = bre.id AND NOT acn.deleted
  23. WHERE bre.id > 0 AND acn IS NULL AND (bre.source IS NULL OR bre.source IN (1,2)) AND NOT bre.deleted AND bre.create_date < NOW() - :period
  24. )
  25. DELETE FROM biblio.record_entry
  26. WHERE id IN
  27. (SELECT id
  28.  FROM empty_bib);
Add Comment
Please, Sign In to add comment