3 SELECT evergreen.upgrade_deps_block_check('0778', :eg_version);
5 CREATE OR REPLACE FUNCTION extract_marc_field_set
6 (TEXT, BIGINT, TEXT, TEXT) RETURNS SETOF TEXT AS $$
14 FROM oils_xpath_table(
15 'id', 'marc', $1, $3, 'id = ' || $2)
16 AS t(id int, t text))x
18 IF $4 IS NOT NULL THEN
19 SELECT INTO output (SELECT regexp_replace(output, $4, '', 'g'));
25 $$ LANGUAGE PLPGSQL IMMUTABLE;
28 CREATE OR REPLACE FUNCTION
29 public.extract_acq_marc_field_set ( BIGINT, TEXT, TEXT)
30 RETURNS SETOF TEXT AS $$
31 SELECT extract_marc_field_set('acq.lineitem', $1, $2, $3);
35 CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $function$
44 FOR adef IN SELECT *,tableoid FROM acq.lineitem_attr_definition LOOP
46 SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid;
48 IF (atype NOT IN ('lineitem_usr_attr_definition','lineitem_local_attr_definition')) THEN
49 IF (atype = 'lineitem_provider_attr_definition') THEN
50 SELECT provider INTO prov FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
51 CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider;
54 IF (atype = 'lineitem_provider_attr_definition') THEN
55 SELECT xpath INTO xpath_string FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
56 ELSIF (atype = 'lineitem_marc_attr_definition') THEN
57 SELECT xpath INTO xpath_string FROM acq.lineitem_marc_attr_definition WHERE id = adef.id;
58 ELSIF (atype = 'lineitem_generated_attr_definition') THEN
59 SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id;
62 xpath_string := REGEXP_REPLACE(xpath_string,$re$//?text\(\)$$re$,'');
64 IF (adef.code = 'title' OR adef.code = 'author') THEN
65 -- title and author should not be split
66 -- FIXME: once oils_xpath can grok XPATH 2.0 functions, we can use
67 -- string-join in the xpath and remove this special case
68 SELECT extract_acq_marc_field(id, xpath_string, adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
69 IF (value IS NOT NULL AND value <> '') THEN
70 INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
71 VALUES (NEW.id, adef.id, atype, adef.code, value);
76 -- each application of the regex may produce multiple values
78 SELECT * FROM extract_acq_marc_field_set(
79 NEW.id, xpath_string || '[' || pos || ']', adef.remove)
82 IF (value IS NOT NULL AND value <> '') THEN
83 INSERT INTO acq.lineitem_attr
84 (lineitem, definition, attr_type, attr_name, attr_value)
85 VALUES (NEW.id, adef.id, atype, adef.code, value);
103 $function$ LANGUAGE PLPGSQL;