From 460912af7c39cc0a933538948da61b46ea50f833 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 12 Jan 2021 00:47:00 -0500 Subject: [PATCH] aggregate attributes to the price level --- db_schema/extract_for_customer_facing.pg.sql | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/db_schema/extract_for_customer_facing.pg.sql b/db_schema/extract_for_customer_facing.pg.sql index 6099a6f..1f50d92 100644 --- a/db_schema/extract_for_customer_facing.pg.sql +++ b/db_schema/extract_for_customer_facing.pg.sql @@ -228,9 +228,27 @@ ORDER BY ,agg_levels AS ( SELECT stlc - ,jsonb_agg(DISTINCT coltier) coltier - ,jsonb_agg(branding) - ,jsonb_agg(DISTINCT - ,jsonb_agg(DISTINCT - ,jsonb_agg(DISTINCT + ,string_agg(DISTINCT coltier ,', ') FILTER (WHERE clist IS NOT NULL) coltier + ,string_agg(DISTINCT branding,', ') branding + ,string_agg(DISTINCT accs ,', ') accs + ,string_agg(DISTINCT suffix ,', ') suffix + ,pckg + ,col + ,vol_uom + ,voL_qty + ,price + ,regexp_replace(jsonb_arr_aggcd(clist)::text,'["\[\]]|null, ','','g') clist + FROM + joinback_init + GROUP BY + stlc + ,pckg + ,col + ,vol_uom + ,vol_qty + ,price ) +SELECT + * +FROM + agg_levels