tps/new_format.pgsql

22 lines
14 KiB
Plaintext
Raw Normal View History

2017-10-03 01:47:30 -04:00
2017-09-19 07:17:38 -04:00
WITH j AS (
SELECT
$${"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-09-19 07:17:38 -04:00
)
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->'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"
$$::jsonb
)
*/