From 21cb531e56b42060c0eecf4e54608fde9a0cfe4b Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 13 Feb 2020 11:03:42 -0500 Subject: [PATCH] embed the module in the forecast pool instead of reading the json, cross join the newly inserted log file and id --- route_sql/build/build_fcpool.sql | 7 +++++-- route_sql/scale_vd.sql | 9 ++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/route_sql/build/build_fcpool.sql b/route_sql/build/build_fcpool.sql index d46ce14..77440a2 100644 --- a/route_sql/build/build_fcpool.sql +++ b/route_sql/build/build_fcpool.sql @@ -102,7 +102,7 @@ SELECT ,iter ,null::int logid ,null::text "comment" - ,null::text iterdet + ,null::text module FROM rlarp.osmf_dev o LEFT OUTER JOIN lgdat.cust bc ON @@ -135,4 +135,7 @@ CREATE INDEX osm_qr ON rlarp.osm_pool(quota_rep_descr); DROP TABLE IF EXISTS rlarp.osm_log; -CREATE TABLE IF NOT EXISTS rlarp.osm_log(id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, doc jsonb); \ No newline at end of file +CREATE TABLE IF NOT EXISTS rlarp.osm_log(id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, doc jsonb); + +GRANT ALL ON TABLE rlarp.osm_log TO api; +GRANT ALL ON TABLE rlarp.osm_pool TO api; \ No newline at end of file diff --git a/route_sql/scale_vd.sql b/route_sql/scale_vd.sql index 931a711..b793c63 100644 --- a/route_sql/scale_vd.sql +++ b/route_sql/scale_vd.sql @@ -4,11 +4,9 @@ target AS (select incr_qty qincr) SELECT sum(units) tot ,sum(units) FILTER (WHERE iter = 'copy') base - ,sum(units) FILTER (WHERE l.doc->>'type' = 'new basket') newpart + ,sum(units) FILTER (WHERE module = 'new basket') newpart FROM rlarp.osm_pool p - INNER JOIN rlarp.osm_log l ON - l.id = p.logid WHERE -----------------scenario---------------------------- where_clause @@ -93,7 +91,7 @@ target AS (select incr_qty qincr) AND CASE (SELECT flag FROM flagv) WHEN 'scale all' THEN true WHEN 'scale copy' THEN iter = 'copy' - WHEN 'scale new part' THEN iterdef->>'type' = 'new basket' + WHEN 'scale new part' THEN module = 'new basket' END AND calc_status||flag <> 'CLOSEDREMAINDER' --exclude short ships when building order adjustments AND order_date <= ship_date @@ -199,10 +197,11 @@ target AS (select incr_qty qincr) ,'replace_source'||' volume' iter ,log.id ,log.doc->>'comment' "comment" - ,'replace_iterdet' iterdet + ,log.doc->>'type' module FROM basemix b CROSS JOIN scale s + CROSS JOIN log ) --select sum(value_usd), count(*) from final , ins AS (