From c9c97fa2676b2d3083e618ada5d7b9e3903103a2 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 24 Aug 2017 22:57:21 -0400 Subject: [PATCH] updates --- event_log.pgsql | 36 +++++++++++++++++++++++++++++------- rec.json | 6 ++++++ 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 rec.json diff --git a/event_log.pgsql b/event_log.pgsql index fba1daf..16d6ef6 100644 --- a/event_log.pgsql +++ b/event_log.pgsql @@ -1,7 +1,29 @@ -SELECT - 'MODULE', - '2017-06-01'::DATE pdate, - '2017-06-01'::DATE tdate, - $${"attribute1":"value","attribute2":"value","attribute3":"value","attribute4":"value","attribute5":"value","attribute5":"value"}$$::jsonb, - $${"account":"amount"}$$::jsonb ledger - +WITH +x AS ( +SELECT +$$ +{"vendor":"Drug Mart","date":"2017-08-20","instrument":"Discover Card","item":[{"item":"Green Chili","amount":1.49},{"item":"Black Beans","amount":1.6},{"item":"Distilled Water","amount":7.12},{"item":"Fruit Preservative","amount":3.99},{"item":"Watch Battery","amount":3.79},{"item":"Sales Tax","amount":"0.26"}],"account":[{"account":"food","offset":"dcard","amount":1.49},{"account":"food","offset":"dcard","amount":1.6},{"account":"food","offset":"dcard","amount":7.12},{"account":"food","offset":"dcard","amount":3.99},{"account":"stuff","offset":"dcard","amount":3.79},{"account":"taxes","offset":"dcard","amount":"0.26"}]} +$$::jsonb j +), +acct AS ( +SELECT + rs.*, + row_number() over() rn +FROM + x + JOIN LATERAL jsonb_to_recordset(x.j->'account') rs(account text,"offset" text, amount numeric) ON TRUE +), +item as ( +SELECT + rs.*, + row_number() over() rn +FROM + x + JOIN LATERAL jsonb_to_recordset(x.j->'item') rs(item text, amount numeric) ON TRUE +) +select + * +from + item + INNER JOIN acct ON + acct.rn = item.rn \ No newline at end of file diff --git a/rec.json b/rec.json new file mode 100644 index 0000000..9ad6592 --- /dev/null +++ b/rec.json @@ -0,0 +1,6 @@ +{ +"party":"Lowe's", +"reason":"ceiling paint", +"reason":"rollers", +"reason":"plastic sheet" +}