1 -- Evergreen DB patch 0552.unnest_biblio_map_authority_linking.sql
3 -- Replace usage of custom explode_array() function with native unnest()
7 -- check whether patch can be applied
8 SELECT evergreen.upgrade_deps_block_check('0552', :eg_version);
10 CREATE OR REPLACE FUNCTION biblio.map_authority_linking (bibid BIGINT, marc TEXT) RETURNS BIGINT AS $func$
11 DELETE FROM authority.bib_linking WHERE bib = $1;
12 INSERT INTO authority.bib_linking (bib, authority)
15 FROM ( SELECT DISTINCT $1 AS bib,
16 BTRIM(remove_paren_substring(txt))::BIGINT AS authority
17 FROM unnest(oils_xpath('//*[@code="0"]/text()',$2)) x(txt)
18 WHERE BTRIM(remove_paren_substring(txt)) ~ $re$^\d+$$re$
19 ) y JOIN authority.record_entry r ON r.id = y.authority;