functional but only 10k rows something wrong

This commit is contained in:
Paul Trowbridge 2020-11-10 01:12:17 -05:00
parent 8f877450c4
commit a0f78af496

View File

@ -29,7 +29,7 @@ SELECT
string_agg( string_agg(
'LEFT OUTER JOIN fc.perd '||func||' ON'|| 'LEFT OUTER JOIN fc.perd '||func||' ON'||
$$ $$
$$||'(o.'||fkey||' + interval '||format('%L',_interval) ||' ) <@ '||func||'.drange' $$||'(o.'||fkey||' + interval '||format('%L',_interval) ||' )::date <@ '||func||'.drange'
,E'\n') ,E'\n')
INTO INTO
_perd_joins _perd_joins
@ -43,7 +43,7 @@ CREATE TABLE IF NOT EXISTS fc.sql(cmd text PRIMARY KEY, t text );
-------------------------------build a column list----------------------------------------- -------------------------------build a column list-----------------------------------------
SELECT SELECT
string_agg(format('%I',cname),E'\n ,' ORDER BY opos ASC) string_agg('o.'||format('%I',cname),E'\n ,' ORDER BY opos ASC)
INTO INTO
_clist _clist
FROM FROM
@ -55,19 +55,29 @@ WHERE
SELECT SELECT
string_agg( string_agg(
format('%I',cname) ||
---instead of directly incrementing the column here, do it in the table join to fc.perd and use that modified date
CASE CASE
WHEN _date_funcs ? func AND dtype = 'date' --if you're dealing with a date function...
THEN ' + interval ''1 year''' WHEN _date_funcs ? func THEN
ELSE '' CASE
--...but it's not the date itself...
WHEN fkey IS NULL THEN
--...pull the associated date field from perd table
func||'.'||m.dateref
--...and it's the primary key date...
ELSE
--use the date key but increment by the target interval
--this assumes that the primary key for the func is a date, but it has to be or it wont join anyways
'o.'||fkey||' + interval '||format('%L',_interval)
END
ELSE
'o.'||format('%I',cname)
END END
,E'\n ,' ORDER BY opos ASC ,E'\n ,' ORDER BY opos ASC
) )
INTO INTO
_clist_inc _clist_inc
FROM FROM
fc.target_meta fc.target_meta m
WHERE WHERE
func NOT IN ('version'); func NOT IN ('version');
@ -131,9 +141,9 @@ SELECT
FROM FROM
baseline o$$||E'\n'||_perd_joins||$$ baseline o$$||E'\n'||_perd_joins||$$
WHERE WHERE
$$||_order_date||$$ + interval '1 year' >= $$||'[app_first_order_date_year]' $$||_order_date||' >= [app_first_forecast_date]'||$$
--the final forecast baseline should have orders greater than or equal to the OR $$||_ship_date||' >= [app_first_forecast_date]'
--start of the year since new orders is the intended forecast --any orders in the forecast period, or any sales in the forecast period (from open orders)
INTO INTO
_baseline; _baseline;