From aa5f2a0a51199368a0f789f0ded7ad3271315fe7 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 10 Nov 2023 02:04:16 -0500 Subject: [PATCH] vault backup: 2023-11-10 02:04:16 --- sql/get_guidance_dseg.pg.sql | 5 +++-- sql/get_hist.pg.sql | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sql/get_guidance_dseg.pg.sql b/sql/get_guidance_dseg.pg.sql index dae4f74..f048cba 100644 --- a/sql/get_guidance_dseg.pg.sql +++ b/sql/get_guidance_dseg.pg.sql @@ -10,6 +10,7 @@ DECLARE --_ship text; --_qty numeric; --_seas int; + _prem jsonb; _mold text; _item text; _cust text; @@ -148,8 +149,8 @@ BEGIN --RAISE NOTICE 'list: %', jsonb_pretty(_list); ----------------get premium for quote hist gap-------------- - --SELECT coalesce(rlarp.get_premium(_stlc, _seas, (SELECT xchan FROM _chx WHERE chan = _chan),_v1ds, ((_rslt->'mostRelevantCustomerPriceInfo')->'source')->>'v1ds'),'{}'::jsonb) INTO _prem; - --_rslt := _rslt||_prem; + SELECT coalesce(rlarp.get_premium(_stlc, _seas, (SELECT xchan FROM _chx WHERE chan = _chan),_rslt->'hist'->'cust'->>'ds', _v1ds),'{}'::jsonb) INTO _prem; + _rslt := _rslt||_prem; --RAISE NOTICE 'list: %', jsonb_pretty(_list); RETURN _rslt; diff --git a/sql/get_hist.pg.sql b/sql/get_hist.pg.sql index 740dbeb..f7658bd 100644 --- a/sql/get_hist.pg.sql +++ b/sql/get_hist.pg.sql @@ -119,9 +119,10 @@ FROM --,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC) best jsonb_strip_nulls( jsonb_build_object( - relevance + flag.source ,jsonb_build_object( - 'avgunits' ,avgunits + 'relevance' ,relevance + ,'avgunits' ,avgunits ,'avgordcount' ,avgordcount ,'avgcustcount' ,avgcustcount ,'avgtargetprice' ,avgtargetprice @@ -135,6 +136,7 @@ FROM ) ) ) doc + ,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC) rnk FROM flag LEFT OUTER JOIN rel ON @@ -143,7 +145,7 @@ FROM relevance ~ 'vol|exact' ) --SELECT jsonb_pretty(jsonb_agg(doc)) FROM rel_sort -SELECT jsonb_obj_aggc(doc) INTO _result FROM rel_sort; +SELECT jsonb_obj_aggc(doc) INTO _result FROM rel_sort WHERE rnk = 1; RETURN _result;