From ea9664801881d0977487e36374b4ead1e17d90db Mon Sep 17 00:00:00 2001 From: scottmk Date: Thu, 28 Jan 2010 14:06:23 +0000 Subject: [PATCH] Oops: need to coalesce before summing, not after. M Open-ILS/src/sql/Pg/200.schema.acq.sql M Open-ILS/src/sql/Pg/002.schema.config.sql A Open-ILS/src/sql/Pg/upgrade/0142.schema.acq.fund_debit_total_view.sql git-svn-id: svn://svn.open-ils.org/ILS/trunk@15394 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/200.schema.acq.sql | 2 +- .../Pg/upgrade/0142.schema.acq.fund_debit_total_view.sql | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0142.schema.acq.fund_debit_total_view.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 8e8e61621..9772acac5 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0141'); -- Scott McKellar +INSERT INTO config.upgrade_log (version) VALUES ('0142'); -- Scott McKellar CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql index a3ae738b0..a5c035dc7 100644 --- a/Open-ILS/src/sql/Pg/200.schema.acq.sql +++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql @@ -851,7 +851,7 @@ CREATE OR REPLACE VIEW acq.fund_allocation_total AS CREATE OR REPLACE VIEW acq.fund_debit_total AS SELECT fund.id AS fund, fund_debit.encumbrance AS encumbrance, - COALESCE( SUM(fund_debit.amount), 0 ) AS amount + SUM( COALESCE( fund_debit.amount, 0 ) ) AS amount FROM acq.fund AS fund LEFT JOIN acq.fund_debit AS fund_debit ON ( fund.id = fund_debit.fund ) diff --git a/Open-ILS/src/sql/Pg/upgrade/0142.schema.acq.fund_debit_total_view.sql b/Open-ILS/src/sql/Pg/upgrade/0142.schema.acq.fund_debit_total_view.sql new file mode 100644 index 000000000..affc8f0d7 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0142.schema.acq.fund_debit_total_view.sql @@ -0,0 +1,14 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0142'); -- Scott McKellar + +CREATE OR REPLACE VIEW acq.fund_debit_total AS + SELECT fund.id AS fund, + fund_debit.encumbrance AS encumbrance, + SUM( COALESCE( fund_debit.amount, 0 ) ) AS amount + FROM acq.fund AS fund + LEFT JOIN acq.fund_debit AS fund_debit + ON ( fund.id = fund_debit.fund ) + GROUP BY 1,2; + +COMMIT; -- 2.11.0