From 15b515a5e173f01950e9500e96da174b22fd087d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 5 Nov 2020 23:58:29 -0500 Subject: [PATCH] begin unioning in the piece used to plug the remainder of the year to create a full baseline --- generate_sql/col_baseline.sql | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/generate_sql/col_baseline.sql b/generate_sql/col_baseline.sql index 434e81d..89b39e7 100644 --- a/generate_sql/col_baseline.sql +++ b/generate_sql/col_baseline.sql @@ -1,11 +1,13 @@ DO -$$ +$func$ DECLARE _clist text; _ytdbody text; _order_date text; _ship_date text; _order_status text; + _actpy text; + _sql text; BEGIN @@ -51,10 +53,33 @@ INTO _ytdbody; --RAISE NOTICE '%', _ytdbody; +SELECT +$$ + ,'baseline' "version" + ,'plug' iter +FROM + rlarp.osm_dev o + LEFT OUTER JOIN gld ON + gld.fspr = o.fspr + LEFT OUTER JOIN gld ss ON + greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat +WHERE + [target_odate] BETWEEN [target_odate_plug_from] AND [target_odate_plug_to] + --be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships +$$ +INTO + _actpy; -INSERT INTO fc.sql SELECT 'baseline', _ytdbody ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t; +SELECT + _ytdbody + ||$$UNION ALL + $$||_actpy +INTO + _sql; + +INSERT INTO fc.sql SELECT 'baseline', _sql ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t; END -$$; +$func$; -SELECT * FROM fc.sql; +---SELECT * FROM fc.sql;