From 562e56be078353b4fd379769c9223a53e20b7c5d Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Thu, 8 Apr 2021 11:52:01 +0200 Subject: [PATCH] sql --- .../src/main/resources/sql/importDedupEvents.sql | 8 ++++++++ .../src/main/resources/sql/someConsistencyQueries.sql | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 apps/dnet-orgs-database-application/src/main/resources/sql/someConsistencyQueries.sql diff --git a/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql b/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql index 146050e3..927faa7f 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql +++ b/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql @@ -50,4 +50,12 @@ WHERE c1.oid != c2.oid ON CONFLICT DO NOTHING; + +-- CONSISTENCY + +-- Remove invalid suggestions (an existing relation has already been approved) +DELETE FROM oa_duplicates d +USING oa_duplicates d1 +WHERE d.oa_original_id = d1.oa_original_id AND d.reltype = 'suggested' AND d1.reltype = 'is_similar'; + COMMIT; diff --git a/apps/dnet-orgs-database-application/src/main/resources/sql/someConsistencyQueries.sql b/apps/dnet-orgs-database-application/src/main/resources/sql/someConsistencyQueries.sql new file mode 100644 index 00000000..89ee3fec --- /dev/null +++ b/apps/dnet-orgs-database-application/src/main/resources/sql/someConsistencyQueries.sql @@ -0,0 +1,2 @@ +-- TO RESOLVE MANUALLY MANAGING CONFLICTS +select d.oa_original_id, array_agg(o.id), array_agg(o.name) from oa_duplicates d left outer join organizations o on (o.id = d.local_id) where d.reltype='is_similar' group by oa_original_id having count(reltype) > 1 and count (distinct o.status) = 1;