Advertisement
roganhamby

Annual Cleanup - Dewey

Jul 8th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. call number dewey / generic clean up
  4.  
  5. */
  6.  
  7. /* first, find the call number ids to be cleaned up by using using names of shelving locations
  8. shelving locations -> copy -> call number
  9.  
  10. 1 generic
  11. 2 dewey
  12. 3 library of congress
  13.  
  14. so we want to ignore those that are already dewey which will make it easier to do smaller cleanups in the future
  15.  
  16.  */
  17.  
  18. drop table if exists rogan.dewey_cleanup_acns;
  19.  
  20. create table rogan.dewey_cleanup_acns as
  21. select acn.id
  22. from (
  23.     select aou.shortname, acl.name, acl.id as acl_id
  24.     from asset.copy_location acl
  25.     join actor.org_unit aou on aou.id = acl.owning_lib
  26.     where acl.name ilike '%non%' and acl.name ilike '%fiction%'
  27.     and acl.name not ilike '%dvd%' and acl.name not ilike '%cd%'
  28.     and acl.name not ilike '%audio%' and acl.name not ilike '%video%'
  29.     ) a
  30. join asset.copy ac on ac.location = a.acl_id
  31. join asset.call_number acn on acn.id = ac.call_number
  32. where acn.label_class != 2
  33. ;
  34.  
  35. select count(id) from rogan.dewey_cleanup_acns;
  36.  
  37. alter table rogan.dewey_cleanup_acns add column converted boolean default false;
  38.  
  39. update asset.call_number set label_class = 2 where id in
  40.     (select id from rogan.dewey_cleanup_acns where converted = false order by id limit 20000);
  41. update rogan.dewey_cleanup_acns set converted = true where id in
  42.     (select id from rogan.dewey_cleanup_acns where converted = false order by id limit 20000);
  43.  
  44. select count(id) from rogan.dewey_cleanup_acns where converted = TRUE;
  45.  
  46.  
  47. drop table if exists rogan.dewey_cleanup_acns;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement