From 86656f69528162b1f6eab256eaf40d6cf9fca2c7 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 29 Apr 2024 08:41:01 -0400 Subject: [PATCH] example pool record selection --- sql/consume_pricepool.pg.sql | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 sql/consume_pricepool.pg.sql diff --git a/sql/consume_pricepool.pg.sql b/sql/consume_pricepool.pg.sql new file mode 100644 index 0000000..e61608d --- /dev/null +++ b/sql/consume_pricepool.pg.sql @@ -0,0 +1,33 @@ +SELECT + gset.cust + ,gset.vers + ,gset.chan + ,gset.nurs + ,gset.ghse + ,gset.mold + ,gset.v1ds + ,gset.v0ds + ,je.k + ,seas.* +FROM + rlarp.price_pool_dev p + LEFT JOIN LATERAL jsonb_to_record(p.gset) AS gset( + chan text + ,mold text + ,v1ds text + ,v0ds text + ,cust text + ,vers text + ,nurs text + ,ghse text + ) ON TRUE + LEFT JOIN LATERAL jsonb_each(p.season) je(k,v) on true + LEFT JOIN Lateral jsonb_to_record(je.v) as seas( + units numeric + ,sales_usd numeric + ,price_usd numeric + ) ON TRUE +WHERE + gset @> '{"mold":"TFR001G0","v0ds":"BASE"}' + AND agglevel ?| array['chan', 'mold', 'v0ds'] + AND NOT agglevel ?| array['cust','ghse'];