include files from iter branch; need to be reviewed

This commit is contained in:
Paul Trowbridge 2022-04-12 12:48:05 -04:00
parent 95675428a4
commit b47630cf61
4 changed files with 195 additions and 0 deletions

111
setup_sql/clone.sql Normal file
View File

@ -0,0 +1,111 @@
CREATE TABLE IF NOT EXISTS fc.live AS (
SELECT
o."ddord#"
,o."dditm#"
,o."fgbol#"
,o."fgent#"
,o."diinv#"
,o."dilin#"
,o.quoten
,o.quotel
,o.dcodat
,o.ddqdat
,o.dcmdat
,o.fesdat
,o.dhidat
,o.fesind
,o.dhpost
,o.fspr
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.diext
,o.ditdis
,o.discj
,o.dhincr
,o.plnt
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.remit_to
,o.bill_class
,o.bill_cust
,o.bill_rep
,o.bill_terr
,o.ship_class
,o.ship_cust
,o.ship_rep
,o.ship_terr
,o.dsm
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.chansub
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.bill_ctry
,o.bill_prov
,o.bill_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.styc
,o.colc
,o.colgrp
,o.coltier
,o.colstat
,o.sizc
,o.pckg
,o.kit
,o.brnd
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldco
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.ddunit
,o.unti
,o.lbs
,o.plt
,o.plcd
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.fb_qty
,o.fb_val_loc
,o.fb_val_loc_dis
,o.fb_val_loc_qt
,o.fb_val_loc_pl
,o.fb_val_loc_tar
,o.fb_cst_loc
,o.fb_cst_loc_cur
,o.fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate
,o.oseas
,o.rdate
,o.rseas
,o.sdate
,o.sseas
,o.version
,o.iter
,null::text AS _comment
,null::integer AS _logid
,null::text AS _tag
FROM
rlarp.osm_dev o
) WITH DATA;

31
setup_sql/clone_meta.sql Normal file
View File

@ -0,0 +1,31 @@
BEGIN;
INSERT INTO
fc.target_meta
SELECT
--hard-coded name of new clone table
'fc.live' tname
,cname
,opos
,func
,fkey
,pretty
,dtype
,mastcol
,appcol
,dateref
FROM
fc.target_meta
WHERE
--hard-coded original sales data with mapped fields
tname = 'rlarp.osm_dev'
ON CONFLICT ON CONSTRAINT target_meta_pk DO UPDATE SET
func = EXCLUDED.func
,pretty = EXCLUDED.pretty
,mastcol = EXCLUDED.mastcol
,appcol = EXCLUDED.appcol
,dateref = EXCLUDED.dateref
,fkey = EXCLUDED.fkey;
--SELECT * FROM fc.target_meta WHERE tname = 'fc.live';
--ROLLBACK;
COMMIT;
END;

49
setup_sql/gen_clone.sql Normal file
View File

@ -0,0 +1,49 @@
DO
$func$
DECLARE
_clist text;
_targ text;
_sql text;
BEGIN
-----------------------------this target would be replaced with a parameter--------------
SELECT
'rlarp.osm_dev o'
INTO
_targ;
-------------------------------build a column list-----------------------------------------
-----------a list of required columns is in fc.appcols, if they are not present------------
-----------they will have to build included------------------------------------------------
SELECT
string_agg(
--if the colum name is empty that means we are dealig with a required appcol
--that isn't present: use the appcol.col for the name preceded by underscore
CASE WHEN m.cname IS NULL
THEN COALESCE(a.dflt,'null::'||a.dtype)||' AS _'||a.col
ELSE 'o.'||format('%I',COALESCE(cname,''))
END
,E'\n ,' ORDER BY opos ASC)
INTO
_clist
FROM
fc.target_meta m
FULL OUTER JOIN fc.appcols a ON
m.appcol = a.col
AND m.dtype = a.dtype
WHERE
tname = _targ;
_sql:= $$CREATE TABLE IF NOT EXISTS fc.live AS (
SELECT
$$||_clist||$$
FROM
$$||_targ||$$
) WITH DATA;$$;
--RAISE NOTICE '%', _sql;
INSERT INTO fc.sql SELECT 'live', _sql ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t;
END;
$func$

View File

@ -0,0 +1,4 @@
# execure the sql for scale which builds the sql and inserts into a table
$PGD -f gen_clone.sql
# pull the sql out of the table and write it to route directory
$PGD -c "SELECT t FROM fc.sql WHERE cmd = 'clone'" -t -A -o clone.sql