From: Dan Scott Date: Wed, 15 Jun 2011 01:34:15 +0000 (-0400) Subject: Avoid duplicate row issues in biblio.extract_located_uris X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7e6d2bfd7e9a5cbe57e4aacdf0b4b015a566883d;p=working%2FEvergreen.git Avoid duplicate row issues in biblio.extract_located_uris As there is currently no unique constraint on the non-ID columns of asset.uri, ensure that we only select a single ID from the tables until we dedupe the tables. Use an ORDER BY to grab the matching row with the lowest ID so we can clear out the rows with higher IDs. Signed-off-by: Dan Scott --- diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql index 7e86d47ba3..17a238332d 100644 --- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql +++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql @@ -880,16 +880,26 @@ BEGIN -- look for a matching uri IF uri_use IS NULL THEN - SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction IS NULL AND active; + SELECT id INTO uri_id + FROM asset.uri + WHERE label = uri_label AND href = uri_href AND use_restriction IS NULL AND active + ORDER BY id LIMIT 1; IF NOT FOUND THEN -- create one INSERT INTO asset.uri (label, href, use_restriction) VALUES (uri_label, uri_href, uri_use); - SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction IS NULL AND active; + SELECT id INTO uri_id + FROM asset.uri + WHERE label = uri_label AND href = uri_href AND use_restriction IS NULL AND active; END IF; ELSE - SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active; + SELECT id INTO uri_id + FROM asset.uri + WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active + ORDER BY id LIMIT 1; IF NOT FOUND THEN -- create one INSERT INTO asset.uri (label, href, use_restriction) VALUES (uri_label, uri_href, uri_use); - SELECT id INTO uri_id FROM asset.uri WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active; + SELECT id INTO uri_id + FROM asset.uri + WHERE label = uri_label AND href = uri_href AND use_restriction = uri_use AND active; END IF; END IF;