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