]> git.evergreen-ils.org Git - contrib/Conifer.git/commit
Updating MARC records using a database function
authorDan Scott <dscott@laurentian.ca>
Thu, 13 Nov 2014 20:44:48 +0000 (15:44 -0500)
committerDan Scott <dscott@laurentian.ca>
Thu, 13 Nov 2014 20:44:48 +0000 (15:44 -0500)
commit3aa6f05bff0958b80d72cb9331ae7d2948c9c00b
treebae9083de1706e8b565d56ca00fac66b98a195af
parent6d68a5bccf4a27ce74e626705f7b3c6067e3998b
Updating MARC records using a database function

There are often debates around the best way to run a batch update of
records in an Evergreen database. My preferred way is to do it using
a PostgreSQL function so that you can simply invoke it as part of a
typical UPDATE statement (including getting as complex as you like
with the surrounding SELECT statements, keeping track of updates in
a separate table, etc).

This example does the following:

* updates 856 $9 subfields that currently have 'OSUL' as a value
  to 'LUSYS'
* deletes any 856 fields that have a $9 value of 'WINDSYS'
* deletes any 506 fields that have a $9 value of 'OWA'

** NOTE: $9 is a repeatable subfield, so strictly speaking you should
   iterate through all of the matching subfields before deleting or
   blindly updating the value... but in our system, we have followed
   the convention of a single 856 per URL and $9, so we're safe. Your
   mileage may vary.

With this function, you can test your work by doing a simple

SELECT conifer.osul_to_lusys(<record-id>);

statement, then actually issue the update using something like:

UPDATE biblio.record_entry
  SET marc = conifer.osul_to_lusys(2683915)
  WHERE id = 2683915;

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/sql/Pg/update_marc_records_in_database.sql [new file with mode: 0644]