add intermediate selects, add coalesce to target aggregation since some items are SQL null, then apply a strip_nulls, but exclude from subsequent step. add update line at end
This commit is contained in:
parent
fb93f73b6c
commit
bf8e901ffd
@ -77,6 +77,7 @@ FROM
|
|||||||
m.regex->>'function' = 'replace'
|
m.regex->>'function' = 'replace'
|
||||||
WHERE
|
WHERE
|
||||||
t.srce = 'PNCC'
|
t.srce = 'PNCC'
|
||||||
|
--rec @> '{"Description":"CHECK 93013270 086129935"}'::jsonb
|
||||||
ORDER BY
|
ORDER BY
|
||||||
t.id DESC,
|
t.id DESC,
|
||||||
m.target,
|
m.target,
|
||||||
@ -84,6 +85,8 @@ ORDER BY
|
|||||||
COALESCE(mt.rn,rp.rn,1)
|
COALESCE(mt.rn,rp.rn,1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--SELECT * FROM rx
|
||||||
|
|
||||||
, agg_to_target_items AS (
|
, agg_to_target_items AS (
|
||||||
SELECT
|
SELECT
|
||||||
srce
|
srce
|
||||||
@ -137,14 +140,16 @@ GROUP BY
|
|||||||
,retain_key
|
,retain_key
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--SELECT * FROM agg_to_target_items
|
||||||
|
|
||||||
, agg_to_target AS (
|
, agg_to_target AS (
|
||||||
SELECT
|
SELECT
|
||||||
srce
|
srce
|
||||||
,id
|
,id
|
||||||
,target
|
,target
|
||||||
,map_intention
|
,map_intention
|
||||||
,tps.jsonb_concat_obj(map_val) map_val
|
,tps.jsonb_concat_obj(COALESCE(map_val,'{}'::JSONB)) map_val
|
||||||
,tps.jsonb_concat_obj(retain_val) retain_val
|
,jsonb_strip_nulls(tps.jsonb_concat_obj(COALESCE(retain_val,'{}'::JSONB))) retain_val
|
||||||
FROM
|
FROM
|
||||||
agg_to_target_items
|
agg_to_target_items
|
||||||
GROUP BY
|
GROUP BY
|
||||||
@ -156,6 +161,10 @@ ORDER BY
|
|||||||
id
|
id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
--SELECT * FROM agg_to_target
|
||||||
|
|
||||||
|
|
||||||
, link_map AS (
|
, link_map AS (
|
||||||
SELECT
|
SELECT
|
||||||
a.srce
|
a.srce
|
||||||
@ -163,7 +172,7 @@ SELECT
|
|||||||
,a.target
|
,a.target
|
||||||
,a.map_intention
|
,a.map_intention
|
||||||
,a.map_val
|
,a.map_val
|
||||||
,jsonb_strip_nulls(a.retain_val) retain_value
|
,a.retain_val retain_value
|
||||||
,v.map
|
,v.map
|
||||||
FROM
|
FROM
|
||||||
agg_to_target a
|
agg_to_target a
|
||||||
@ -173,6 +182,9 @@ FROM
|
|||||||
v.retval = a.map_val
|
v.retval = a.map_val
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--SELECT * FROM link_map
|
||||||
|
|
||||||
|
, agg_to_id AS (
|
||||||
SELECT
|
SELECT
|
||||||
srce
|
srce
|
||||||
,id
|
,id
|
||||||
@ -183,4 +195,18 @@ FROM
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
srce
|
srce
|
||||||
,id
|
,id
|
||||||
|
)
|
||||||
|
|
||||||
|
--SELECT * FROM agg_to_id
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
tps.trans t
|
||||||
|
SET
|
||||||
|
map = o.map,
|
||||||
|
parse = o.retain_val,
|
||||||
|
allj = t.rec||o.map||o.retain_val
|
||||||
|
FROM
|
||||||
|
agg_to_id o
|
||||||
|
WHERE
|
||||||
|
o.id = t.id;
|
Loading…
Reference in New Issue
Block a user