From: Thomas Berezansky Date: Thu, 29 Sep 2011 14:44:26 +0000 (-0400) Subject: Use DISTINCT in counts to avoid dupes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=dbbb3a30c5f3fdfbd7f423e399d0e3707f4ae515;p=contrib%2FConifer.git Use DISTINCT in counts to avoid dupes Otherwise you get: Legacy count + 2(normal count)(aged count) Signed-off-by: Thomas Berezansky Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/sql/Pg/extend-reporter.sql b/Open-ILS/src/sql/Pg/extend-reporter.sql index 3643631d44..cb7eec54a9 100644 --- a/Open-ILS/src/sql/Pg/extend-reporter.sql +++ b/Open-ILS/src/sql/Pg/extend-reporter.sql @@ -26,7 +26,7 @@ CREATE TABLE extend_reporter.legacy_circ_count ( ); CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS - SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(circ.id), 0::bigint) + COALESCE(count(acirc.id), 0::bigint) AS circ_count + SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(DISTINCT circ.id), 0::bigint) + COALESCE(count(DISTINCT acirc.id), 0::bigint) AS circ_count FROM asset."copy" cp LEFT JOIN extend_reporter.legacy_circ_count c USING (id) LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql index eb558c32a6..2107adc250 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql @@ -1,5 +1,5 @@ CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS - SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(circ.id), 0::bigint) + COALESCE(count(acirc.id), 0::bigint) AS circ_count + SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(DISTINCT circ.id), 0::bigint) + COALESCE(count(DISTINCT acirc.id), 0::bigint) AS circ_count FROM asset."copy" cp LEFT JOIN extend_reporter.legacy_circ_count c USING (id) LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id