vault backup: 2023-11-01 15:12:18

This commit is contained in:
Paul Trowbridge 2023-11-01 15:12:18 -04:00
parent 10e3a2cb8a
commit a836d2ce24
2 changed files with 28 additions and 55 deletions

View File

@ -2,14 +2,17 @@ SELECT
gset
,agglevel
,e.k
,e.v->>'units'
,e.v->>'price_usd'
,e.v->>'target_price'
,e.v->>'units' units
,e.v->>'price_usd' price_usd
,e.v->>'target_price' target_price
FROM
rlarp.price_pool_dev
JOIN LATERAL JSONB_EACH(season) e(k,v) ON TRUE
LEFT JOIN LATERAL JSONB_EACH(season) e(k,v) ON TRUE
WHERE
gset @> '{"baseitem":"XNS0T1G3"}'::jsonb
--gset @> '{"mold":"XNS0T1G3"}'::jsonb
gset @> jsonb_build_object(
'mold','TUH10000',
'vers','A'
)
ORDER BY
agglevel ASC
;
agglevel ASC;

View File

@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
agg AS (
SELECT
o.customer
,substring(o.version,1,1) version
,o.chanwide
,o.nursery_region
,c.greenhouse_region
@ -57,6 +58,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
--AND i.coltier <> 'C'
GROUP BY
o.customer
,substring(o.version,1,1)
,o.chanwide
,o.nursery_region
,c.greenhouse_region
@ -76,6 +78,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
jsonb_strip_nulls(
jsonb_build_object(
'cust' ,customer
,'vers' ,version
,'chan' ,chanwide
,'nurs' ,nursery_region
,'ghse' ,greenhouse_region
@ -84,6 +87,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
,'v0ds' ,v0dataseg
)
) gset
,version
,oseas
,sum(units ) units
,sum(sales_usd) sales_usd
@ -92,20 +96,22 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
,jsonb_agg(DISTINCT coltier) coltier
FROM
agg
GROUP BY GROUPING SETS (
-- oseas baseitem v0datseg chanwide customer region v1dataseg --
(oseas, baseitem, chanwide, v0dataseg, customer )
,(oseas, baseitem, chanwide, customer, v1dataseg )
,(oseas, baseitem, chanwide, v0dataseg )
,(oseas, baseitem, chanwide, v0dataseg, nursery_region )
,(oseas, baseitem, chanwide, v0dataseg, greenhouse_region )
,(oseas, baseitem, chanwide, v1dataseg )
,(oseas, baseitem, chanwide, v0dataseg, nursery_region )
,(oseas, baseitem, chanwide, v0dataseg, greenhouse_region )
GROUP BY
version
,GROUPING SETS (
-- oseas version, baseitem v0datseg chanwide customer region v1dataseg --
(oseas, version, baseitem, chanwide, v0dataseg, customer )
,(oseas, version, baseitem, chanwide, customer, v1dataseg )
,(oseas, version, baseitem, chanwide, v0dataseg )
,(oseas, version, baseitem, chanwide, v0dataseg, nursery_region )
,(oseas, version, baseitem, chanwide, v0dataseg, greenhouse_region )
,(oseas, version, baseitem, chanwide, v1dataseg )
,(oseas, version, baseitem, chanwide, v0dataseg, nursery_region )
,(oseas, version, baseitem, chanwide, v0dataseg, greenhouse_region )
)
)
SELECT
gset
gset
,jsonb_object_agg(oseas,jsonb_build_object('units',units,'sales_usd',sales_usd,'price_usd',price_usd,'target_price',target_price)) season
,(SELECT JSONB_AGG(k.v ORDER BY k.v ASC) FROM jsonb_object_keys(gset) k(v)) agglevel
--,oseas
@ -114,45 +120,9 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
--,price_usd
FROM
gsets
where
WHERE
oseas IS NOT NULL
--AND gset @> jsonb_build_object('baseitem', 'XNS0T1G3')
GROUP BY
gset
) WITH DATA;
--UPDATE
-- rlarp.osm_stack o
--SET
-- pricing = o.pricing||jsonb_build_object('us_dirdrp',g.season)
--FROM
-- rlarp.price_pool g
--WHERE
-- o.version IN ('Actual','Quotes')
-- AND g.gset = jsonb_build_object('baseitem',o.baseitem,'v0dataseg',o.v0dataseg,'chanwide','D','greenhouse_region','US');
--
--UPDATE
-- rlarp.osm_stack o
--SET
-- pricing = o.pricing||jsonb_build_object('us_dirdrp_v1',g.season)
--FROM
-- rlarp.price_pool g
--WHERE
-- o.version IN ('Actual','Quotes')
-- AND g.gset = jsonb_build_object('baseitem',o.baseitem,'v0dataseg',v0dataseg,'v1dataseg',o.dataseg,'chanwide','D');
--END
--$func$
--SELECT
-- jsonb_build_object('baseitem',o.baseitem,'v1dataseg',o.dataseg,'chanwide','D')
-- ,g.season
-- ,o.pricing||jsonb_build_object('us_dirdrp_v1',g.season)
--FROM
-- rlarp.osm_stack o
-- LEFT OUTER JOIN rlarp.price_pool g ON
-- g.gset = jsonb_build_object('baseitem',o.baseitem,'v0dataseg',v0dataseg,'v1dataseg',o.dataseg,'chanwide','D')
--WHERE
-- o.version IN ('Actual','Quotes')
-- AND o.baseitem = 'HSI06000'
--LIMIT 100