diff --git a/tables/core_target.pg.sql b/tables/core_target.pg.sql index 59d229f..4bda31f 100644 --- a/tables/core_target.pg.sql +++ b/tables/core_target.pg.sql @@ -14,28 +14,3 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON pricequote.target_prices TO PUBLIC; DROP TABLE IF EXISTS import.core_target; CREATE TABLE import.core_target AS (SELECT * FROM pricequote.core_target); - -WITH -expand AS ( -SELECT - c.compset, - c.stlc, - c.floor, - b.ds, - b.chan, - b.tier, - b.vol, - b.val, - b.price, - json_pretty(to_json(b.math)) math -FROM - pricequote.core_target c - LEFT JOIN LATERAL pricequote.build_pricing_path_base (options||jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')) b ON b.lastflag -) --- select count(*) from expand -INSERT INTO - pricequote.target_prices_base -SELECT - * -FROM - expand diff --git a/tables/rebuild_targets.pg.sql b/tables/rebuild_targets.pg.sql new file mode 100644 index 0000000..9224f59 --- /dev/null +++ b/tables/rebuild_targets.pg.sql @@ -0,0 +1,27 @@ + +DELETE FROM pricequote.target_prices_base; + +WITH +expand AS ( +SELECT + c.compset, + c.stlc, + c.floor, + b.ds, + b.chan, + b.tier, + b.vol, + b.val, + b.price, + b.math math +FROM + pricequote.core_target c + LEFT JOIN LATERAL pricequote.build_pricing_path_base (options||jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')) b ON b.lastflag +) +-- select count(*) from expand +INSERT INTO + pricequote.target_prices_base +SELECT + * +FROM + expand; diff --git a/tables/target_prices_base.pg.sql b/tables/target_prices_base.pg.sql new file mode 100644 index 0000000..74d0e56 --- /dev/null +++ b/tables/target_prices_base.pg.sql @@ -0,0 +1,17 @@ +DROP TABLE pricequote.target_prices_base CASCADE; + +CREATE TABLE pricequote.target_prices_base ( + compset TEXT NOT NULL, + stlc TEXT NOT NULL, + floor NUMERIC NOT NULL, + ds TEXT NOT NULL, + chan TEXT NOT NULL, + tier TEXT NOT NULL, + vol INT4RANGE NOT NULL, + val NUMERIC NOT NULL, + price NUMERIC, + math TEXT[], + PRIMARY KEY (stlc, ds, chan, tier, vol) +); + +GRANT SELECT, INSERT, UPDATE, DELETE ON pricequote.target_prices_base TO PUBLIC; diff --git a/tables/target_prices_view.pg.sql b/tables/target_prices_view.pg.sql index 386f8fa..1261820 100644 --- a/tables/target_prices_view.pg.sql +++ b/tables/target_prices_view.pg.sql @@ -8,4 +8,4 @@ SELECT ,price ,to_jsonb(math)::text AS math FROM - pricequote.target_prices; \ No newline at end of file + pricequote.target_prices_base;