This commit is contained in:
Paul Trowbridge 2017-08-24 22:57:21 -04:00
parent 4c6f4f04b0
commit c9c97fa267
2 changed files with 35 additions and 7 deletions

View File

@ -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

6
rec.json Normal file
View File

@ -0,0 +1,6 @@
{
"party":"Lowe's",
"reason":"ceiling paint",
"reason":"rollers",
"reason":"plastic sheet"
}