From 5ec3f1d9c1d2660842dcde00aeb43ea251ca76ac Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 8 Sep 2025 08:50:28 -0400 Subject: [PATCH] put target rebuild in a proc --- tables/rebuild_targets.pg.sql | 55 +++++++++++++++++------------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/tables/rebuild_targets.pg.sql b/tables/rebuild_targets.pg.sql index 4e3113b..f371a62 100644 --- a/tables/rebuild_targets.pg.sql +++ b/tables/rebuild_targets.pg.sql @@ -1,29 +1,28 @@ -BEGIN; -DELETE FROM pricequote.target_prices_base; +CREATE OR REPLACE PROCEDURE pricequote.refresh_target_prices_base() +LANGUAGE plpgsql +AS $$ +BEGIN + 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; - -COMMIT; \ No newline at end of file + WITH expand AS ( + SELECT + c.compset, + c.stlc, + c.floor, + b.ds, + b.chan, + b.tier, + b.vol, + b.val, + b.price, + b.math AS math + FROM pricequote.core_target c + LEFT JOIN LATERAL pricequote.build_pricing_path_base( + c.options || jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price') + ) AS b + ON b.lastflag + ) + INSERT INTO pricequote.target_prices_base + SELECT * FROM expand; +END; +$$;