22 lines
8.6 KiB
PL/PgSQL
22 lines
8.6 KiB
PL/PgSQL
|
|
WITH j AS (
|
|
SELECT
|
|
$${"vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card","module":"MJE_O","offset":"dcard","total":111.41,"vend item":[{"vend item":"GE CHIPS","amt":2.5,"account":"food","item":"chips","reason":"food","qty":1,"uom":"bag","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"},{"vend item":"GE CHIPS","amt":2.5,"account":"food","item":"chips","reason":"food","qty":1,"uom":"bag","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"},{"vend item":"GE CHIPS","amt":2.5,"account":"food","item":"chips","reason":"food","qty":1,"uom":"bag","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"},{"vend item":"GE CHIPS","amt":-2.19,"account":"food","item":"discount","reason":"food","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"},{"vend item":"GE CHIPS","amt":-2.5,"account":"dcard","item":"chips","reason":"food","qty":1,"uom":"bag","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"},{"vend item":"GE CHIPS","amt":-2.5,"account":"dcard","item":"chips","reason":"food","qty":1,"uom":"bag","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"},{"vend item":"GE CHIPS","amt":-2.5,"account":"dcard","item":"chips","reason":"food","qty":1,"uom":"bag","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"},{"vend item":"GE CHIPS","amt":2.19,"account":"dcard","item":"discount","reason":"food","vendor":"Giant Eagle","date":"10/1/2017","instrument":"Discover Card"}]}$$::JSONB as r
|
|
)
|
|
select
|
|
a.i->>'amt',
|
|
a.i->>'account',
|
|
a.i->>'date',
|
|
a.i - '{amt,account,date}'::text[] as therest
|
|
FROM
|
|
j
|
|
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS(j.r->'vend item') a(i) ON TRUE
|
|
|
|
/*
|
|
SELECT
|
|
jsonb_pretty(
|
|
$$
|
|
{"vendor":"Acme","date":"9/19/2017","instrument":"Discover Card","module":"MJE_O","offset":"dcard","total":127.66,"item":[{"item":"sun chips","amt":3.29,"account":"food","reason":"chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"cheetos paws","amt":3.69,"account":"food","reason":"chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"jif","amt":4.99,"account":"food","reason":"peanut butter","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"jif whips","amt":3.99,"account":"food","reason":"peanut butter","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"jif","amt":4.99,"account":"food","reason":"peanut butter","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"goya chipotle pepp","amt":2.29,"account":"food","reason":"chili peppers","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"quick oats","amt":4.69,"account":"food","reason":"oats","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"quick oats","amt":4.69,"account":"food","reason":"oats","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"sara lee artesano","amt":2.99,"account":"food","reason":"bread","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"dan lgt yog","amt":3.29,"account":"food","reason":"yogurt","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"bananas","amt":3.7,"account":"food","reason":"bananas","qty":7.11,"uom":"lbs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"yellow onions","amt":2.99,"account":"food","reason":"onions","qty":3,"uom":"lbs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"orange peppers","amt":4.11,"account":"food","reason":"peppers","qty":1.03,"uom":"lbs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"asparagus","amt":5.14,"account":"food","reason":"asparagus","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"broccoli","amt":2.99,"account":"food","reason":"broccoli","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"hn fat free frank","amt":5.49,"account":"food","reason":"hot dogs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"hn fat free frank","amt":5.49,"account":"food","reason":"hot dogs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"butterscotch morsels","amt":3.49,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"chocolate chips","amt":3.49,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"chocolate chips","amt":3.49,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"chocolate chips","amt":3.49,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"chocolate chips","amt":3.49,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"seedless grapes","amt":11.45,"account":"food","reason":"grapes","qty":2.87,"uom":"lbs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"honecrisp apples","amt":14.76,"account":"food","reason":"apples","qty":3.7,"uom":"lbs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"garlic expressions","amt":4.99,"account":"food","reason":"salad dressing","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"olivegarden dressing","amt":3.49,"account":"food","reason":"salad dressing","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"garlic expressions","amt":4.99,"account":"food","reason":"salad dressing","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"thomas cinamon bagels","amt":4.69,"account":"food","reason":"bagels","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"stawberries","amt":1.25,"account":"food","reason":"strawberries","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"stawberries","amt":1.25,"account":"food","reason":"strawberries","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"provolone cheese","amt":6.99,"account":"food","reason":"cheese","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"lemon juice","amt":1.99,"account":"food","reason":"lemon juice","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"cucumbers","amt":1.99,"account":"food","reason":"cucumbers","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"cucumbers","amt":1.99,"account":"food","reason":"cucumbers","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"distilled water","amt":"0.89","account":"food","reason":"water","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"distilled water","amt":"0.89","account":"food","reason":"water","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"distilled water","amt":"0.89","account":"food","reason":"water","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"distilled water","amt":"0.89","account":"food","reason":"water","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"distilled water","amt":"0.89","account":"food","reason":"water","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"distilled water","amt":"0.89","account":"food","reason":"water","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-1.7,"account":"food","reason":"chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-0.99,"account":"food","reason":"broccoli","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-1.5,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-1.5,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-1.5,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-1.5,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-1.5,"account":"food","reason":"chocolate chips","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-8.03,"account":"food","reason":"grapes","qty":2.87,"uom":"lbs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"},{"item":"discount","amt":-5.55,"account":"food","reason":"apples","qty":3.7,"uom":"lbs","vendor":"Acme","date":"9/19/2017","instrument":"Discover Card"}]}
|
|
$$::jsonb
|
|
)
|
|
*/ |