dates can't have foriegn key, need to operate off appcol and func.
This commit is contained in:
parent
57051675b3
commit
aa4d6fb7f0
@ -36,7 +36,7 @@ SELECT format('%I',max(schema))||'.'||format('%I',max(tname)) INTO _target_table
|
||||
--the target interval
|
||||
SELECT interval '1 year' INTO _interval;
|
||||
SELECT cname INTO _version_col FROM fc.target_meta WHERE appcol = 'version';
|
||||
SELECT jsonb_agg(func) INTO _date_funcs FROM fc.target_meta WHERE dtype = 'date' AND fkey is NOT null;
|
||||
SELECT jsonb_agg(func) INTO _date_funcs FROM fc.target_meta WHERE dtype = 'date' AND appcol is NOT null;
|
||||
--create table join for each date based func in target_meta joining to fc.perd static table
|
||||
--the join, though, should be based on the target date, which is needs an interval added to get to the target
|
||||
SELECT
|
||||
@ -51,7 +51,9 @@ FROM
|
||||
fc.target_meta
|
||||
WHERE
|
||||
dtype = 'date'
|
||||
AND fkey IS NOT NULL;
|
||||
AND func IS NOT NULL;
|
||||
|
||||
raise notice '%',_perd_joins;
|
||||
|
||||
-------------------------------build a column list-----------------------------------------
|
||||
SELECT
|
||||
@ -61,8 +63,9 @@ INTO
|
||||
FROM
|
||||
fc.target_meta
|
||||
WHERE
|
||||
func NOT IN ('version');
|
||||
COALESCE(appcol,'') NOT IN ('version','iter','logid');
|
||||
|
||||
raise notice '%',_clist;
|
||||
---------------------------build column to increment dates---------------------------------
|
||||
|
||||
SELECT
|
||||
@ -72,9 +75,9 @@ SELECT
|
||||
WHEN _date_funcs ? func THEN
|
||||
CASE
|
||||
--...but it's not the date itself...
|
||||
WHEN fkey IS NULL THEN
|
||||
WHEN appcol IS NULL THEN
|
||||
--...pull the associated date field from perd table
|
||||
func||'.'||m.fcol
|
||||
'perd.'||m.fcol
|
||||
--...and it's the primary key date...
|
||||
ELSE
|
||||
--use the date key but increment by the target interval
|
||||
@ -91,9 +94,9 @@ INTO
|
||||
FROM
|
||||
fc.target_meta m
|
||||
WHERE
|
||||
func NOT IN ('version');
|
||||
COALESCE(appcol,'') NOT IN ('version','iter','logid');
|
||||
|
||||
--RAISE NOTICE 'build list: %',clist;
|
||||
RAISE NOTICE 'DATES INCREMENTED: %',_clist_inc;
|
||||
|
||||
--------------------------------------clone the actual baseline-----------------------------------------------
|
||||
|
||||
@ -104,6 +107,7 @@ $$SELECT
|
||||
$$
|
||||
,'forecast_name' "version"
|
||||
,'actuals' iter
|
||||
,null::bigint app_logid
|
||||
FROM
|
||||
$$||_target_table||$$ o
|
||||
WHERE
|
||||
@ -120,7 +124,7 @@ $$::text
|
||||
INTO
|
||||
_ytdbody;
|
||||
|
||||
--RAISE NOTICE '%', _ytdbody;
|
||||
RAISE NOTICE '_ytdbody %', _ytdbody;
|
||||
|
||||
|
||||
------------------------------------pull a plug from actuals to create a full year baseline------------------
|
||||
@ -131,6 +135,7 @@ $$SELECT
|
||||
$$
|
||||
,'forecast_name' "version"
|
||||
,'plug' iter
|
||||
,null::bigint app_logid
|
||||
FROM
|
||||
$$||_target_table||' o'||E'\n'||_perd_joins||$$
|
||||
WHERE
|
||||
@ -140,6 +145,7 @@ $$
|
||||
INTO
|
||||
_actpy;
|
||||
|
||||
RAISE NOTICE '_actpf %',_actpy;
|
||||
------------------------------copy a full year and increment by 1 year for the baseline-------------------------
|
||||
|
||||
SELECT
|
||||
@ -151,6 +157,7 @@ SELECT
|
||||
$$
|
||||
,'forecast_name' "version"
|
||||
,'baseline' iter
|
||||
,null::bigint app_logid
|
||||
FROM
|
||||
baseline o$$||E'\n'||_perd_joins||$$
|
||||
)
|
||||
@ -172,6 +179,7 @@ INTO
|
||||
_baseline;
|
||||
|
||||
|
||||
RAISE NOTICE '_baseline %',_baseline;
|
||||
------------------------------stack the sql into the final format------------------------------------------------
|
||||
|
||||
SELECT
|
||||
@ -186,6 +194,8 @@ $$||_baseline
|
||||
INTO
|
||||
_sql;
|
||||
|
||||
RAISE NOTICE '_sql %',_sql;
|
||||
|
||||
INSERT INTO fc.sql SELECT 'baseline', _sql ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t;
|
||||
|
||||
END
|
||||
|
Loading…
Reference in New Issue
Block a user