embed the module in the forecast pool instead of reading the json, cross join the newly inserted log file and id

This commit is contained in:
Paul Trowbridge 2020-02-13 11:03:42 -05:00
parent eddece49e1
commit 21cb531e56
2 changed files with 9 additions and 7 deletions

View File

@ -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
@ -136,3 +136,6 @@ 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);
GRANT ALL ON TABLE rlarp.osm_log TO api;
GRANT ALL ON TABLE rlarp.osm_pool TO api;

View File

@ -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 (