add the notion of an appcolumn, and use it to push into variables to generate route sql
This commit is contained in:
parent
d9bfe43d2e
commit
fcac081823
@ -1,15 +1,21 @@
|
|||||||
DO
|
DO
|
||||||
$$
|
$$
|
||||||
DECLARE
|
DECLARE
|
||||||
clist text;
|
_clist text;
|
||||||
ytdbody text;
|
_ytdbody text;
|
||||||
|
_order_date text;
|
||||||
|
_ship_date text;
|
||||||
|
_order_status text;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
|
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(format('%I',cname),E'\n ,' ORDER BY opos ASC)
|
||||||
INTO
|
INTO
|
||||||
clist
|
_clist
|
||||||
FROM
|
FROM
|
||||||
fc.target_meta
|
fc.target_meta
|
||||||
WHERE
|
WHERE
|
||||||
@ -17,11 +23,14 @@ WHERE
|
|||||||
|
|
||||||
--RAISE NOTICE 'build list: %',clist;
|
--RAISE NOTICE 'build list: %',clist;
|
||||||
|
|
||||||
|
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_date') INTO _order_date;
|
||||||
|
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'ship_date') INTO _ship_date;
|
||||||
|
SELECT (SELECT cname FROM fc.target_meta WHERE appcol = 'order_status') INTO _order_status;
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
$a$
|
$a$SELECT
|
||||||
SELECT
|
|
||||||
$a$::text||
|
$a$::text||
|
||||||
clist||
|
_clist||
|
||||||
$b$
|
$b$
|
||||||
,'baseline' "version"
|
,'baseline' "version"
|
||||||
,'actuals' iter
|
,'actuals' iter
|
||||||
@ -30,18 +39,22 @@ FROM
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
[order date column name] BETWEEN [supplied target range from date] AND [supplied target range to date]
|
$b$||_order_date||$c$ BETWEEN [app_baseline_from_date] AND [app_baseline_to_date]
|
||||||
--...or any open orders currently booked before cutoff....
|
--...or any open orders currently booked before cutoff....
|
||||||
OR ([order status column here] IN ([list of statuses indicating still open]) and [order date column name] <= [include open orders through this date])
|
OR ($c$||_order_status||$d$ IN ([app_openstatus_code]) and $d$||_order_date||$e$ <= [app_openorder_cutoff])
|
||||||
--...or anything that shipped in that period
|
--...or anything that shipped in that period
|
||||||
OR ([name of shipdate column] BETWEEN [supplied target range from date] AND [supplied target range to date])
|
OR ($e$||_ship_date||$f$ BETWEEN [app_baseline_from_date] AND [app_baseline_to_date])
|
||||||
)
|
)
|
||||||
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
$b$::text
|
$f$::text
|
||||||
INTO
|
INTO
|
||||||
ytdbody;
|
_ytdbody;
|
||||||
|
|
||||||
RAISE NOTICE '%', ytdbody;
|
--RAISE NOTICE '%', _ytdbody;
|
||||||
|
|
||||||
|
INSERT INTO fc.sql SELECT 'baseline', _ytdbody ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t;
|
||||||
|
|
||||||
END
|
END
|
||||||
$$
|
$$;
|
||||||
|
|
||||||
|
SELECT * FROM fc.sql;
|
||||||
|
@ -35,3 +35,5 @@ to-do:
|
|||||||
* problem: how will the incremented order season get updated, adding an interval won't work
|
* problem: how will the incremented order season get updated, adding an interval won't work
|
||||||
* a table fc.odate, has been built, but it is incomplete, a setup function filling in these date-keyed tables could be setup
|
* a table fc.odate, has been built, but it is incomplete, a setup function filling in these date-keyed tables could be setup
|
||||||
* if a table is date-keyed, fc.perd could be targeted to fill in the gaps
|
* if a table is date-keyed, fc.perd could be targeted to fill in the gaps
|
||||||
|
* the target sales data has to map have concepts like order_date, and the application needs to know which col is order date
|
||||||
|
* add column called application hook
|
||||||
|
@ -10,9 +10,19 @@ CREATE TABLE fc.target_meta (
|
|||||||
,pretty text
|
,pretty text
|
||||||
,dtype text
|
,dtype text
|
||||||
,mastcol text
|
,mastcol text
|
||||||
|
,appcol text
|
||||||
);
|
);
|
||||||
|
|
||||||
--ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk;
|
--ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk;
|
||||||
ALTER TABLE fc.target_meta ADD CONSTRAINT target_meta_pk PRIMARY KEY (tname, cname);
|
ALTER TABLE fc.target_meta ADD CONSTRAINT target_meta_pk PRIMARY KEY (tname, cname);
|
||||||
|
|
||||||
COMMENT ON TABLE fc.target_meta IS 'target table layout info';
|
COMMENT ON TABLE fc.target_meta IS 'target table layout info';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.tname IS 'schema.table_name of target sales data table';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.cname IS 'column name';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.opos IS 'ordinal position of column';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.func IS 'a functional entity (like customer, part number) that master tables will be build from';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.fkey IS 'primary key for functional entity';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.pretty IS 'the presentation name of the column';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.dtype IS 'data type of the sales table column';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.mastcol IS 'associated field from the master data table if it is different (oseas would refer to ssyr in fc.perd)';
|
||||||
|
COMMENT ON COLUMN fc.target_meta.appcol IS 'supply column name to be used for application variables - (specifcy the order date column)';
|
||||||
|
Loading…
Reference in New Issue
Block a user