trim retained values

This commit is contained in:
Paul Trowbridge 2017-10-26 17:34:21 -04:00
parent 6a90cc4b32
commit 7eba5981ef

View File

@ -1,4 +1,4 @@
\timing
WITH WITH
--------------------apply regex operations to transactions----------------------------------------------------------------------------------- --------------------apply regex operations to transactions-----------------------------------------------------------------------------------
@ -53,11 +53,11 @@ SELECT
CASE regex->>'function' CASE regex->>'function'
WHEN 'extract' THEN WHEN 'extract' THEN
CASE WHEN array_upper(mt.mt,1)=1 CASE WHEN array_upper(mt.mt,1)=1
THEN to_json(mt.mt[1]) THEN to_json(trim(mt.mt[1]))
ELSE array_to_json(mt.mt) ELSE array_to_json(mt.mt)
END::jsonb END::jsonb
WHEN 'replace' THEN WHEN 'replace' THEN
to_jsonb(rp.rp) to_jsonb(rtrim(rp.rp))
ELSE ELSE
'{}'::jsonb '{}'::jsonb
END END
@ -76,7 +76,8 @@ FROM
LEFT JOIN LATERAL regexp_replace(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text, e.v ->> 'replace'::text,e.v ->> 'flag') WITH ORDINALITY rp(rp, rn) ON LEFT JOIN LATERAL regexp_replace(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text, e.v ->> 'replace'::text,e.v ->> 'flag') WITH ORDINALITY rp(rp, rn) ON
m.regex->>'function' = 'replace' m.regex->>'function' = 'replace'
WHERE WHERE
t.srce = 'PNCC' --t.srce = 'PNCC'
rec @> '{"Transaction":"ACH Credits","Transaction":"ACH Debits"}'
--rec @> '{"Description":"CHECK 93013270 086129935"}'::jsonb --rec @> '{"Description":"CHECK 93013270 086129935"}'::jsonb
ORDER BY ORDER BY
t.id DESC, t.id DESC,
@ -197,9 +198,9 @@ GROUP BY
,id ,id
) )
--SELECT * FROM agg_to_id SELECT srce, id, jsonb_pretty(retain_val), jsonb_pretty(map) FROM agg_to_id
/*
UPDATE UPDATE
tps.trans t tps.trans t
SET SET
@ -209,4 +210,5 @@ SET
FROM FROM
agg_to_id o agg_to_id o
WHERE WHERE
o.id = t.id; o.id = t.id;
*/