Advertisement
chrissharp123

bib deletion

Dec 8th, 2020
886
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. LEFT JOIN acq.lineitem acqli ON acqli.eg_bib_id = bre.id -- changed "acqli.record" to "acqli.eg_bib_id"
  24. WHERE bre.id > 0 AND acn IS NULL
  25. -- limit source so as to not delete e-resource records, which can be legitimately empty
  26. AND (bre.source IS NULL OR bre.source IN (1, 2, 5))
  27. AND NOT bre.deleted AND bre.create_date < NOW() - :period
  28. AND acqli.state NOT IN ('pending','new')  -- changed "AND NOT" to "NOT IN"
  29. )
  30. DELETE FROM biblio.record_entry
  31. WHERE id IN
  32. (SELECT id
  33.  FROM empty_bib);
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement