From e7e973193a702441c390586c3a6f3e6762c55e69 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 30 Apr 2014 18:38:29 -0400 Subject: [PATCH] LP#1312945: baseline schema update Signed-off-by: Mike Rylander Signed-off-by: Srey Seng Signed-off-by: Galen Charlton --- Open-ILS/src/sql/Pg/999.functions.global.sql | 38 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index ac20ce7a3c..69b77e2df0 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1553,22 +1553,32 @@ BEGIN AND linking_subfield IS NOT NULL AND main_entry IS NOT NULL LOOP - link := SUBSTRING( - (XPATH('//*[@tag="' || acsaf.tag || '"]/*[@code="' || - acsaf.linking_subfield || '"]/text()', rec_marc_xml))[1]::TEXT, - '\d+$' - ); + -- Loop over the trailing-number contents of all linking subfields + FOR link IN + SELECT SUBSTRING( x::TEXT, '\d+$' ) + FROM UNNEST( + XPATH( + '//*[@tag="' + || acsaf.tag + || '"]/*[@code="' + || acsaf.linking_subfield + || '"]/text()', + rec_marc_xml + ) + ) x + LOOP - -- Ignore links that are null, malformed, circular, or point to - -- non-existent authority records. - IF link IS NOT NULL AND link::BIGINT <> rec_id THEN - PERFORM * FROM authority.record_entry WHERE id = link::BIGINT; - IF FOUND THEN - aal.target := link::BIGINT; - aal.field := acsaf.id; - RETURN NEXT aal; + -- Ignore links that are null, malformed, circular, or point to + -- non-existent authority records. + IF link IS NOT NULL AND link::BIGINT <> rec_id THEN + PERFORM * FROM authority.record_entry WHERE id = link::BIGINT; + IF FOUND THEN + aal.target := link::BIGINT; + aal.field := acsaf.id; + RETURN NEXT aal; + END IF; END IF; - END IF; + END LOOP; END LOOP; END; $func$ LANGUAGE PLPGSQL; -- 2.11.0