only assign a map if an item actually joins to map_rv

This commit is contained in:
Paul Trowbridge 2017-10-20 01:04:56 -04:00
parent ea0084ed75
commit 7abb8ce65d

View File

@ -31,7 +31,8 @@ FROM
LEFT JOIN LATERAL jsonb_array_elements(m.regex->'defn') WITH ORDINALITY e(v, rn) ON true LEFT JOIN LATERAL jsonb_array_elements(m.regex->'defn') WITH ORDINALITY e(v, rn) ON true
LEFT JOIN LATERAL regexp_matches(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text) WITH ORDINALITY mt(mt, rn) ON true LEFT JOIN LATERAL regexp_matches(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text) WITH ORDINALITY mt(mt, rn) ON true
WHERE WHERE
t.srce = 'DCARD' t.map IS NULL
AND t.srce = 'DCARD'
ORDER BY ORDER BY
m.srce, m.srce,
m.seq, m.seq,
@ -76,12 +77,12 @@ agg_rx AS (
u.rec, u.rec,
string_agg(u.target,',') target, string_agg(u.target,',') target,
tps.jsonb_concat_obj(coalesce(v.map,'{}'::jsonb) ORDER BY seq ) map, tps.jsonb_concat_obj(coalesce(v.map,'{}'::jsonb) ORDER BY seq ) map,
tps.jsonb_concat_obj(u.retval||coalesce(v.map,'{}'::jsonb) ORDER BY seq) comb, --tps.jsonb_concat_obj(u.retval||coalesce(v.map,'{}'::jsonb) ORDER BY seq) comb,
tps.jsonb_concat_obj(u.retain||coalesce(v.map,'{}'::jsonb) ORDER BY seq) retain tps.jsonb_concat_obj(u.retain||coalesce(v.map,'{}'::jsonb) ORDER BY seq) retain
FROM FROM
--re-aggregate return values and explude any records where one or more regex failed with a null result --re-aggregate return values and explude any records where one or more regex failed with a null result
agg_rx u agg_rx u
LEFT OUTER JOIN tps.map_rv v ON INNER JOIN tps.map_rv v ON
v.target = u.target AND v.target = u.target AND
v.srce = u.srce AND v.srce = u.srce AND
v.retval <@ u.retval v.retval <@ u.retval
@ -92,6 +93,18 @@ agg_rx AS (
) )
--SELECT * FROM agg_orig
--UPDATE tps.trans t SET (map) = (SELECT retain FROM agg_orig WHERE t.id = agg_orig.id);
UPDATE
tps.trans t
SET
map = o.retain
FROM
agg_orig o
WHERE
o.id = t.id
/*
SELECT SELECT
retain->>'f20', retain->>'f20',
rec->>'Description', rec->>'Description',
@ -104,3 +117,4 @@ GROUP BY
ORDER BY ORDER BY
retain->>'f20', retain->>'f20',
rec->>'Description' rec->>'Description'
*/