END;
$func$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION biblio.reingest_uris() RETURNS VOID AS $func$
+DECLARE
+ rec_id BIGINT;
+BEGIN
+ -- Get the distinct set of record IDs that need to be reingested
+ -- (assuming that href = label is a reasonable red flag)
+ FOR rec_id IN SELECT rec_uris.id FROM (
+ SELECT acn.record AS id
+ FROM asset.call_number acn
+ INNER JOIN asset.uri_call_number_map auricnm ON auricnm.call_number = acn.id
+ INNER JOIN asset.uri auri ON auri.id = auricnm.uri
+ WHERE auri.href = auri.label
+ GROUP BY acn.record
+ ORDER BY acn.record
+ ) AS rec_uris
+ LOOP
+ -- Reingest the offending records
+ PERFORM biblio.extract_located_uris(rec_id, bre.marc, 1)
+ FROM biblio.record_entry bre
+ WHERE bre.id = rec_id;
+ END LOOP;
+END;
+$func$ LANGUAGE PLPGSQL;
+-- Kick off the reingest; this may take a while
+SELECT biblio.reingest_uris();