From: Jason Boyer Date: Fri, 15 Mar 2019 19:35:26 +0000 (-0400) Subject: LP1820339: Vandelay Imports on Pg 10 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4ce058763027e724ee2bfc3b339a0dc77ad61107;p=evergreen%2Ftadl.git LP1820339: Vandelay Imports on Pg 10 In vandelay.flatten_marc_hstore there are a couple instances of set-returning functions used inside a CASE statement, which Pg10 is unhappy about. This branch changes these regexp_matches calls to use regexp_match instead which avoids this error. Signed-off-by: Jason Boyer Signed-off-by: Jason Stephenson Signed-off-by: Ben Shum Signed-off-by: Jason Boyer --- diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 18268f465a..5a11ac6816 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -632,9 +632,9 @@ BEGIN FROM (SELECT tag, subfield, CASE WHEN tag = '020' THEN -- caseless -- isbn - LOWER((REGEXP_MATCHES(value,$$^(\S{10,17})$$))[1] || '%') + LOWER((REGEXP_MATCH(value,$$^(\S{10,17})$$))[1] || '%') WHEN tag = '022' THEN -- caseless -- issn - LOWER((REGEXP_MATCHES(value,$$^(\S{4}[- ]?\S{4})$$))[1] || '%') + LOWER((REGEXP_MATCH(value,$$^(\S{4}[- ]?\S{4})$$))[1] || '%') WHEN tag = '024' THEN -- caseless -- upc (other) LOWER(value || '%') ELSE diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1820339-pg10-vandelay.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1820339-pg10-vandelay.sql new file mode 100644 index 0000000000..1f7416cc75 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.lp1820339-pg10-vandelay.sql @@ -0,0 +1,34 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +CREATE OR REPLACE FUNCTION vandelay.flatten_marc_hstore( + record_xml TEXT +) RETURNS HSTORE AS $func$ +BEGIN + RETURN (SELECT + HSTORE( + ARRAY_AGG(tag || (COALESCE(subfield, ''))), + ARRAY_AGG(value) + ) + FROM ( + SELECT tag, subfield, ARRAY_AGG(value)::TEXT AS value + FROM (SELECT tag, + subfield, + CASE WHEN tag = '020' THEN -- caseless -- isbn + LOWER((REGEXP_MATCH(value,$$^(\S{10,17})$$))[1] || '%') + WHEN tag = '022' THEN -- caseless -- issn + LOWER((REGEXP_MATCH(value,$$^(\S{4}[- ]?\S{4})$$))[1] || '%') + WHEN tag = '024' THEN -- caseless -- upc (other) + LOWER(value || '%') + ELSE + value + END AS value + FROM vandelay.flatten_marc(record_xml)) x + GROUP BY tag, subfield ORDER BY tag, subfield + ) subquery + ); +END; +$func$ LANGUAGE PLPGSQL; + +COMMIT;