vault backup: 2023-11-01 15:12:18
This commit is contained in:
parent
10e3a2cb8a
commit
a836d2ce24
17
sql/get.sql
17
sql/get.sql
@ -2,14 +2,17 @@ SELECT
|
|||||||
gset
|
gset
|
||||||
,agglevel
|
,agglevel
|
||||||
,e.k
|
,e.k
|
||||||
,e.v->>'units'
|
,e.v->>'units' units
|
||||||
,e.v->>'price_usd'
|
,e.v->>'price_usd' price_usd
|
||||||
,e.v->>'target_price'
|
,e.v->>'target_price' target_price
|
||||||
FROM
|
FROM
|
||||||
rlarp.price_pool_dev
|
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
|
WHERE
|
||||||
gset @> '{"baseitem":"XNS0T1G3"}'::jsonb
|
--gset @> '{"mold":"XNS0T1G3"}'::jsonb
|
||||||
|
gset @> jsonb_build_object(
|
||||||
|
'mold','TUH10000',
|
||||||
|
'vers','A'
|
||||||
|
)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
agglevel ASC
|
agglevel ASC;
|
||||||
;
|
|
||||||
|
@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
|
|||||||
agg AS (
|
agg AS (
|
||||||
SELECT
|
SELECT
|
||||||
o.customer
|
o.customer
|
||||||
|
,substring(o.version,1,1) version
|
||||||
,o.chanwide
|
,o.chanwide
|
||||||
,o.nursery_region
|
,o.nursery_region
|
||||||
,c.greenhouse_region
|
,c.greenhouse_region
|
||||||
@ -57,6 +58,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
|
|||||||
--AND i.coltier <> 'C'
|
--AND i.coltier <> 'C'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
o.customer
|
o.customer
|
||||||
|
,substring(o.version,1,1)
|
||||||
,o.chanwide
|
,o.chanwide
|
||||||
,o.nursery_region
|
,o.nursery_region
|
||||||
,c.greenhouse_region
|
,c.greenhouse_region
|
||||||
@ -76,6 +78,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
|
|||||||
jsonb_strip_nulls(
|
jsonb_strip_nulls(
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'cust' ,customer
|
'cust' ,customer
|
||||||
|
,'vers' ,version
|
||||||
,'chan' ,chanwide
|
,'chan' ,chanwide
|
||||||
,'nurs' ,nursery_region
|
,'nurs' ,nursery_region
|
||||||
,'ghse' ,greenhouse_region
|
,'ghse' ,greenhouse_region
|
||||||
@ -84,6 +87,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
|
|||||||
,'v0ds' ,v0dataseg
|
,'v0ds' ,v0dataseg
|
||||||
)
|
)
|
||||||
) gset
|
) gset
|
||||||
|
,version
|
||||||
,oseas
|
,oseas
|
||||||
,sum(units ) units
|
,sum(units ) units
|
||||||
,sum(sales_usd) sales_usd
|
,sum(sales_usd) sales_usd
|
||||||
@ -92,20 +96,22 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
|
|||||||
,jsonb_agg(DISTINCT coltier) coltier
|
,jsonb_agg(DISTINCT coltier) coltier
|
||||||
FROM
|
FROM
|
||||||
agg
|
agg
|
||||||
GROUP BY GROUPING SETS (
|
GROUP BY
|
||||||
-- oseas baseitem v0datseg chanwide customer region v1dataseg --
|
version
|
||||||
(oseas, baseitem, chanwide, v0dataseg, customer )
|
,GROUPING SETS (
|
||||||
,(oseas, baseitem, chanwide, customer, v1dataseg )
|
-- oseas version, baseitem v0datseg chanwide customer region v1dataseg --
|
||||||
,(oseas, baseitem, chanwide, v0dataseg )
|
(oseas, version, baseitem, chanwide, v0dataseg, customer )
|
||||||
,(oseas, baseitem, chanwide, v0dataseg, nursery_region )
|
,(oseas, version, baseitem, chanwide, customer, v1dataseg )
|
||||||
,(oseas, baseitem, chanwide, v0dataseg, greenhouse_region )
|
,(oseas, version, baseitem, chanwide, v0dataseg )
|
||||||
,(oseas, baseitem, chanwide, v1dataseg )
|
,(oseas, version, baseitem, chanwide, v0dataseg, nursery_region )
|
||||||
,(oseas, baseitem, chanwide, v0dataseg, nursery_region )
|
,(oseas, version, baseitem, chanwide, v0dataseg, greenhouse_region )
|
||||||
,(oseas, 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
|
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
|
,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
|
,(SELECT JSONB_AGG(k.v ORDER BY k.v ASC) FROM jsonb_object_keys(gset) k(v)) agglevel
|
||||||
--,oseas
|
--,oseas
|
||||||
@ -114,45 +120,9 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
|
|||||||
--,price_usd
|
--,price_usd
|
||||||
FROM
|
FROM
|
||||||
gsets
|
gsets
|
||||||
where
|
WHERE
|
||||||
oseas IS NOT NULL
|
oseas IS NOT NULL
|
||||||
--AND gset @> jsonb_build_object('baseitem', 'XNS0T1G3')
|
--AND gset @> jsonb_build_object('baseitem', 'XNS0T1G3')
|
||||||
GROUP BY
|
GROUP BY
|
||||||
gset
|
gset
|
||||||
) WITH DATA;
|
) 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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user