DROP LANGUAGE plperl;
+\qecho Evergreen depends heavily on each bibliographic record containing
+\qecho a 901 field with a subfield "c" to hold the record ID. The following
+\qecho query identifies the bibs that are missing 901s or whose first
+\qecho 901$c is not equal to the bib ID. This *will* take a long time in a
+\qecho big database; as the schema updates are over now, you can cancel this
+\qecho if you are in a rush.
+
+SELECT id
+ FROM biblio.record_entry
+ WHERE (
+ (XPATH('//marc:datafield[@tag="901"][1]/marc:subfield[@code="c"]/text()', marc::XML, ARRAY[ARRAY['marc', 'http://www.loc.gov/MARC21/slim']]))[1]::TEXT IS NULL
+ OR
+ (XPATH('//marc:datafield[@tag="901"][1]/marc:subfield[@code="c"]/text()', marc::XML, ARRAY[ARRAY['marc', 'http://www.loc.gov/MARC21/slim']]))[1]::TEXT <> id::TEXT)
+ AND id > -1;
+
+\qecho If there are records with missing or incorrect 901$c values, you can
+\qecho generally rely on the triggers in the biblio.record_entry table to
+\qecho populate the 901$c properly; for each offending record, run:
+\qecho UPDATE biblio.record_entry SET marc = marc WHERE id = <id>;