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>