LP#1312945: baseline schema update
authorMike Rylander <mrylander@gmail.com>
Wed, 30 Apr 2014 22:38:29 +0000 (18:38 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 20 May 2014 22:54:33 +0000 (15:54 -0700)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Srey Seng <sreyseng@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/sql/Pg/999.functions.global.sql

index ac20ce7..69b77e2 100644 (file)
@@ -1553,22 +1553,32 @@ BEGIN
             AND linking_subfield IS NOT NULL
             AND main_entry IS NOT NULL
     LOOP
             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 IF;
+        END LOOP;
     END LOOP;
 END;
 $func$ LANGUAGE PLPGSQL;
     END LOOP;
 END;
 $func$ LANGUAGE PLPGSQL;