Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION evergreen.mvlc_populate_bucket(inbucket integer, root_ou integer, checkattrs hstore[], time_period interval DEFAULT '50 years'::interval, maxbibs integer DEFAULT 10000) RETURNS VOID AS
- $FUNC$
- DECLARE
- BEGIN
- -- Does the bookbag exist?
- PERFORM * FROM container.biblio_record_entry_bucket WHERE id = inbucket;
- IF NOT FOUND THEN
- RETURN;
- END IF;
- -- Does the OU exist?
- PERFORM * FROM actor.org_unit WHERE id = root_ou;
- IF NOT FOUND THEN
- RETURN;
- END IF;
- -- Remove old bucket items
- DELETE FROM container.biblio_record_entry_bucket_item WHERE bucket = inbucket;
- -- Populate the bucket
- INSERT INTO container.biblio_record_entry_bucket_item (bucket, target_biblio_record_entry)
- SELECT inbucket, mra.id
- FROM metabib.record_attr mra
- JOIN asset.call_number acn ON mra.id = acn.record
- JOIN asset.copy acp ON acp.call_number = acn.id
- JOIN (SELECT unnest(checkattrs) as inattrs) x ON true
- WHERE attrs @> inattrs
- AND acp.circ_lib IN (SELECT id FROM actor.org_unit_descendants(root_ou))
- GROUP BY mra.id
- HAVING AGE(MIN(acp.active_date)) < time_period
- ORDER BY MIN(acp.active_date) DESC
- LIMIT maxbibs;
- END;
- $FUNC$ LANGUAGE plpgsql;
- -- Example usage
- SELECT evergreen.mvlc_populate_bucket(208942, 1, ARRAY['item_type=>a'::hstore], '30 days'::INTERVAL);
- SELECT evergreen.mvlc_populate_bucket(208943, 1, ARRAY['item_type=>g'::hstore], '30 days'::INTERVAL);
- SELECT evergreen.mvlc_populate_bucket(208944, 1, ARRAY['item_type=>a, item_form=>d'::hstore], '30 days'::INTERVAL);
- SELECT evergreen.mvlc_populate_bucket(208945, 1, ARRAY['item_type=>j'::hstore], '30 days'::INTERVAL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement