build template for applying gl on the server side per item with offset
This commit is contained in:
parent
0b4a638430
commit
caf3ffe3b4
BIN
build_json.xlsx
BIN
build_json.xlsx
Binary file not shown.
46
header_item_template.pgsql
Normal file
46
header_item_template.pgsql
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
\timing
|
||||||
|
with j as (
|
||||||
|
SELECT
|
||||||
|
$$
|
||||||
|
{"header":{"vendor":"Target","date":"10/12/2017","instrument":"Discover Card","module":"hdrio","total":47.74,"location":"Stow, OH","transaction":"purchase","offset":"dcard"},"item":[{"vend item":"HERBAL","amt":7.99,"account":"home supplies","item":"shampoo","reason":"hygiene"},{"vend item":"HERBAL","amt":7.99,"account":"home supplies","item":"conditioner","reason":"hygiene"},{"vend item":"BUILDING SET","amt":28.74,"account":"recreation","item":"legos","reason":"toys","qty":6,"uom":"ea"},{"vend item":"OH TAX","amt":3.02,"account":"sales tax","item":"sales tax","reason":"sales tax","rate":"0.0675"}]}
|
||||||
|
$$::jsonb jb
|
||||||
|
)
|
||||||
|
,os AS (
|
||||||
|
SELECT
|
||||||
|
flag,
|
||||||
|
sign,
|
||||||
|
x.offs
|
||||||
|
FROM
|
||||||
|
j
|
||||||
|
JOIN LATERAL
|
||||||
|
(
|
||||||
|
VALUES
|
||||||
|
('ITEM',1,null),
|
||||||
|
('OFFSET',-1,j.jb->'header'->>'offset')
|
||||||
|
) x (flag, sign, offs) ON TRUE
|
||||||
|
)
|
||||||
|
,build AS (
|
||||||
|
SELECT
|
||||||
|
array['item',rn::text]::text jpath
|
||||||
|
,COALESCE(os.offs,ae.e->>'account') acct
|
||||||
|
,(ae.e->>'amt')::numeric * os.sign amount
|
||||||
|
FROM
|
||||||
|
j
|
||||||
|
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS(J.JB->'item') WITH ORDINALITY ae(e,rn) ON TRUE
|
||||||
|
CROSS JOIN os
|
||||||
|
ORDER BY
|
||||||
|
ae.rn ASC,
|
||||||
|
os.flag ASC
|
||||||
|
)
|
||||||
|
,agg AS (
|
||||||
|
SELECT
|
||||||
|
jsonb_build_object('gl',jsonb_agg(row_to_json(b))) gl
|
||||||
|
FROM
|
||||||
|
build b
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
jsonb_pretty(agg.gl||j.jb)
|
||||||
|
FROM
|
||||||
|
agg
|
||||||
|
CROSS JOIN j
|
||||||
|
|
12
srce.pgsql
12
srce.pgsql
@ -16,21 +16,13 @@ DECLARE _t text;
|
|||||||
DECLARE _c text;
|
DECLARE _c text;
|
||||||
DECLARE _path text;
|
DECLARE _path text;
|
||||||
DECLARE _srce text;
|
DECLARE _srce text;
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
_path := 'C:\users\fleet\downloads\d1026.csv';
|
|
||||||
_srce := 'DCARD';
|
|
||||||
=======
|
|
||||||
DECLARE _log_info text;
|
DECLARE _log_info text;
|
||||||
DECLARE _log_id text;
|
DECLARE _log_id text;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
_path := 'C:\users\ptrowbridge\downloads\llcol.csv';
|
_path := 'C:\users\fleet\downloads\discover-recentactivity-20171031.csv';
|
||||||
_srce := 'PNCL';
|
_srce := 'DCARD';
|
||||||
>>>>>>> wk
|
|
||||||
|
|
||||||
----------------------------------------------------build the column list of the temp table----------------------------------------------------------------
|
----------------------------------------------------build the column list of the temp table----------------------------------------------------------------
|
||||||
|
|
||||||
|
BIN
summary.xlsx
BIN
summary.xlsx
Binary file not shown.
Loading…
Reference in New Issue
Block a user