3 INSERT INTO config.upgrade_log (version) VALUES ('0455'); -- gmc
5 CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $function$
14 FOR adef IN SELECT *,tableoid FROM acq.lineitem_attr_definition LOOP
16 SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid;
18 IF (atype NOT IN ('lineitem_usr_attr_definition','lineitem_local_attr_definition')) THEN
19 IF (atype = 'lineitem_provider_attr_definition') THEN
20 SELECT provider INTO prov FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
21 CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider;
24 IF (atype = 'lineitem_provider_attr_definition') THEN
25 SELECT xpath INTO xpath_string FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
26 ELSIF (atype = 'lineitem_marc_attr_definition') THEN
27 SELECT xpath INTO xpath_string FROM acq.lineitem_marc_attr_definition WHERE id = adef.id;
28 ELSIF (atype = 'lineitem_generated_attr_definition') THEN
29 SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id;
32 xpath_string := REGEXP_REPLACE(xpath_string,$re$//?text\(\)$$re$,'');
34 IF (adef.code = 'title' OR adef.code = 'author') THEN
35 -- title and author should not be split
36 -- FIXME: once oils_xpath can grok XPATH 2.0 functions, we can use
37 -- string-join in the xpath and remove this special case
38 SELECT extract_acq_marc_field(id, xpath_string, adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
39 IF (value IS NOT NULL AND value <> '') THEN
40 INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
41 VALUES (NEW.id, adef.id, atype, adef.code, value);
47 SELECT extract_acq_marc_field(id, xpath_string || '[' || pos || ']', adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
49 IF (value IS NOT NULL AND value <> '') THEN
50 INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
51 VALUES (NEW.id, adef.id, atype, adef.code, value);
66 $function$ LANGUAGE PLPGSQL;