wiki:cataloguingAdding856

Adding 856 fields to existing bibliographic records

It is often the case that you'll need to retroactively add URLs for a specific organization to a bibliographic record that already contains URLs for another organization. In the following example, the record contains an 856 field for Windsor that includes the Windsor proxy and special ebrary collection code.

<datafield xmlns:marc="http://www.loc.gov/MARC21/slim" tag="856" ind1="4" ind2="0">
  <subfield code="u">http://ezproxy.uwindsor.ca/login?url=http://site.ebrary.com/lib/oculwindsor/Doc?id=10304083</subfield>
  <subfield code="z">To view Windsor's electronic resource click here.</subfield>
  <subfield code="9">WINDSYS</subfield>
</datafield>

We can use the regexp_replace() function in PostgreSQL to do a regular expression search and replace; we just need to break down the URL into its constituent elements, replace all those elements to keep the Windsor 856 field, and substitute the Laurentian-specific elements for the new Laurentian 856 field for the record, like so:

BEGIN;
UPDATE biblio.record_entry
  SET marc = regexp_replace(
    marc,
    E'(<datafield xmlns:marc="http://www.loc.gov/MARC21/slim" tag="856".*?code="u">)(http://ezproxy.uwindsor.ca)(.*?)(/oculwindsor/)(.*?code="z">)(.*?)(</subfield>.*?code="9">)(.*?)(</subfield>.*?</datafield>)', 
    E'\\1\\2\\3\\4\\5\\6\\7\\8\\9\\1http://librweb.laurentian.ca\\3/jndlu/\\5Online / En ligne\\7LUSYS\\9'
  )
  WHERE marc ILIKE '%Patron Driven Acquisition%' AND id > 2000000;

The result:

   <datafield xmlns:marc="http://www.loc.gov/MARC21/slim" tag="856" ind1="4" ind2="0">
     <subfield code="u">http://ezproxy.uwindsor.ca/login?url=http://site.ebrary.com/lib/oculwindsor/Doc?id=10304083</subfield>
     <subfield code="z">To view Windsor's electronic resource click here.</subfield>
     <subfield code="9">WINDSYS</subfield>
   </datafield><datafield xmlns:marc="http://www.loc.gov/MARC21/slim" tag="856" ind1="4" ind2="0">
     <subfield code="u">http://librweb.laurentian.ca/login?url=http://site.ebrary.com/lib/jndlu/Doc?id=10304083</subfield>
     <subfield code="z">Online / En ligne</subfield>
     <subfield code="9">LUSYS</subfield>
   </datafield>
Last modified 7 years ago Last modified on Jan 11, 2012, 11:32:08 AM