acq.fund_debit_total, which is used by acq.fund_combined_balance, can
return 2 values, the total encumbered and total spent for a fund. This
patch updates acq.fund_combined_balance to SUM the two so that only 1
row per fund is returned from acq.fund_combined_balance
Signed-off-by: Bill Erickson <berick@esilibrary.com>
CREATE OR REPLACE VIEW acq.fund_combined_balance AS
SELECT c.fund,
- c.amount - COALESCE(d.amount,0.0) AS amount
+ c.amount - SUM( COALESCE(d.amount, 0)) AS amount
FROM acq.fund_allocation_total c
- LEFT JOIN acq.fund_debit_total d USING (fund);
+ LEFT JOIN acq.fund_debit_total d USING (fund) GROUP BY c.fund, c.amount;
CREATE OR REPLACE VIEW acq.fund_spent_balance AS
SELECT c.fund,
--- /dev/null
+-- Evergreen DB patch XXXX.schema.acq.fund-combined-balance.sql.sql
+--
+-- FIXME: insert description of change, if needed
+--
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE VIEW acq.fund_combined_balance AS
+ SELECT
+ c.fund,
+ c.amount - SUM( COALESCE(d.amount, 0) ) AS amount
+ FROM acq.fund_allocation_total c
+ LEFT JOIN acq.fund_debit_total d USING (fund)
+ GROUP BY c.fund, c.amount;
+
+COMMIT;