include pricing and colors in final query

This commit is contained in:
Paul Trowbridge 2021-01-11 23:40:37 -05:00
parent 690b325e78
commit fcdb134b76

View File

@ -1,3 +1,4 @@
--EXPLAIN (ANALYZE, BUFFERS)
WITH
pc AS materialized (
SELECT
@ -31,22 +32,23 @@ SELECT
,pc.branding
,pc.ACCS
,pc.SUFFIX
,string_agg( DISTINCT ltrim(rtrim(i.COLC)),', ') clist
----price 1 -----------------
,pc.PCKG1
,pc.VOLL1
,pc.VOL1_UOM
,pc.VOL1_PRICE
----price 2 -----------------
,pc.PCKG2
,pc.VOLl2
,pc.VOL2_UOM
,pc.VOL2_PRICE
----price 3 -----------------
,pc.PCKG1
,pc.VOLL3
,pc.VOL3_UOM
,pc.VOL3_PRICE
,string_agg( DISTINCT ltrim(rtrim(i.COLC)),', ') tclist
,jsonb_agg( DISTINCT ltrim(rtrim(i.COLC))) clist
------price 1 -----------------
--,pc.PCKG1
--,pc.VOLL1
--,pc.VOL1_UOM
--,pc.VOL1_PRICE
------price 2 -----------------
--,pc.PCKG2
--,pc.VOLl2
--,pc.VOL2_UOM
--,pc.VOL2_PRICE
------price 3 -----------------
--,pc.PCKG1
--,pc.VOLL3
--,pc.VOL3_UOM
--,pc.VOL3_PRICE
FROM
pc
LEFT OUTER JOIN RLARP.ITEMMv i ON
@ -91,6 +93,8 @@ GROUP BY
,1 col
,pc.pckg1 pckg
,pc.vol1_uom vol_uom
,pc.voll1 vol_qty
,pc.vol1_price price
FROM
pc
UNION
@ -103,6 +107,8 @@ GROUP BY
,2 col
,pc.pckg2 pckg
,pc.vol2_uom vol_uom
,pc.voll2 vol_qty
,pc.vol2_price price
FROM
pc
UNION
@ -115,6 +121,8 @@ GROUP BY
,3 col
,pc.pckg3 pckg
,pc.vol3_uom vol_uom
,pc.voll3 vol_qty
,pc.vol3_price price
FROM
pc
)
@ -130,8 +138,25 @@ SELECT
--retain this column to re-pivot back to original format
,up.col
,up.vol_uom
,up.voL_qty
,up.price
,row_number() OVER (PARTITION BY up.stlc, up.coltier, up.branding, up.accs, up.suffix, up.pckg, up.col, up.vol_uom ORDER BY item DESC) seq
,item
--subquery option is not performant at all
--,(
-- SELECT
-- item
-- FROM
-- rlarp.itemmv v
-- WHERE
-- v.stlc = up.stlc
-- AND v.branding = up.branding
-- AND v.accs = up.accs
-- AND v.suffix = up.suffix
-- AND v.uomp ? up.pckg
-- AND v.aplnt <> 'I'
-- LIMIT 1
--) item_subq
FROM
unpivot up
LEFT OUTER JOIN RLARP.ITEMMv i ON
@ -175,13 +200,16 @@ FROM
SELECT
i.*
,c.*
,l.clist
FROM
items_init i
LEFT OUTER JOIN conversion c ON
c.p = i.item
AND c.f = i.vol_uom
NATURAL JOIN colors l
WHERE
i.seq = 1
ORDER BY
stlc
,coltier
,col
i.stlc
,i.coltier
,i.col