.get_marc_tag
authorJason Etheridge <jason@esilibrary.com>
Sat, 21 Feb 2015 01:53:35 +0000 (20:53 -0500)
committerJason Etheridge <jason@esilibrary.com>
Sat, 21 Feb 2015 01:53:35 +0000 (20:53 -0500)
Useful since you can't get unnormalized values out of metabib.full_rec

Signed-off-by: Jason Etheridge <jason@esilibrary.com>

sql/base/base.sql

index aa3e990..896a566 100644 (file)
@@ -2124,3 +2124,18 @@ CREATE OR REPLACE FUNCTION migration_tools.duplicate_template (INTEGER, INTEGER[
     END;
 $$ LANGUAGE PLPGSQL STRICT VOLATILE;
 
+CREATE OR REPLACE FUNCTION migration_tools.get_marc_tag (TEXT, TEXT, TEXT) RETURNS TEXT AS $$
+    my ($marcxml, $tag, $subfield) = @_;
+
+    use MARC::Record;
+    use MARC::File::XML;
+    use MARC::Field;
+
+    my $field;
+    eval {
+        my $marc = MARC::Record->new_from_xml($marcxml, 'UTF-8');
+        $field = $marc->field($tag);
+    };
+    return $field->as_string($subfield);
+$$ LANGUAGE PLPERLU STABLE;
+