1 -- Evergreen DB patch 0649.schema.fix_full_circ_count_view.sql
3 -- FIXME: insert description of change, if needed
8 -- check whether patch can be applied
9 SELECT evergreen.upgrade_deps_block_check('0649', :eg_version);
11 -- FIXME: add/check SQL statements to perform the upgrade
12 CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS
13 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
15 LEFT JOIN extend_reporter.legacy_circ_count c USING (id)
16 LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id
17 LEFT JOIN "action".aged_circulation acirc ON acirc.target_copy = cp.id
18 GROUP BY cp.id, c.circ_count;