include mods to mapping function in initial deploy sql
This commit is contained in:
parent
13929a6e32
commit
8c2936ee54
@ -17,7 +17,7 @@
|
|||||||
"where": [
|
"where": [
|
||||||
{}
|
{}
|
||||||
],
|
],
|
||||||
"function": "replace",
|
"function": "extract",
|
||||||
"description": "pull first 20 characters from description for mapping"
|
"description": "pull first 20 characters from description for mapping"
|
||||||
},
|
},
|
||||||
"sequence": 1
|
"sequence": 1
|
||||||
|
@ -697,9 +697,16 @@ $f$;
|
|||||||
|
|
||||||
-------------------create trigger to map imported items------------------------------------------------------------------------------------------------------
|
-------------------create trigger to map imported items------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER AS $f$
|
CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER
|
||||||
|
AS
|
||||||
|
$f$
|
||||||
|
DECLARE
|
||||||
|
_cnt INTEGER;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
IF (TG_OP = 'INSERT') THEN
|
IF (TG_OP = 'INSERT') THEN
|
||||||
|
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
--------------------apply regex operations to transactions-----------------------------------------------------------------------------------
|
--------------------apply regex operations to transactions-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -710,7 +717,7 @@ CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER AS $f$
|
|||||||
t.rec,
|
t.rec,
|
||||||
m.target,
|
m.target,
|
||||||
m.seq,
|
m.seq,
|
||||||
regex->>'function' regex_function,
|
regex->'regex'->>'function' regex_function,
|
||||||
e.v ->> 'field' result_key_name,
|
e.v ->> 'field' result_key_name,
|
||||||
e.v ->> 'key' target_json_path,
|
e.v ->> 'key' target_json_path,
|
||||||
e.v ->> 'flag' regex_options_flag,
|
e.v ->> 'flag' regex_options_flag,
|
||||||
@ -729,7 +736,7 @@ CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER AS $f$
|
|||||||
END map_key,
|
END map_key,
|
||||||
CASE e.v->>'map'
|
CASE e.v->>'map'
|
||||||
WHEN 'y' THEN
|
WHEN 'y' THEN
|
||||||
CASE regex->>'function'
|
CASE regex->'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(mt.mt[1])
|
||||||
@ -751,7 +758,7 @@ CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER AS $f$
|
|||||||
END retain_key,
|
END retain_key,
|
||||||
CASE e.v->>'retain'
|
CASE e.v->>'retain'
|
||||||
WHEN 'y' THEN
|
WHEN 'y' THEN
|
||||||
CASE regex->>'function'
|
CASE regex->'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(trim(mt.mt[1]))
|
THEN to_json(trim(mt.mt[1]))
|
||||||
@ -767,15 +774,15 @@ CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER AS $f$
|
|||||||
END retain_val
|
END retain_val
|
||||||
FROM
|
FROM
|
||||||
tps.map_rm m
|
tps.map_rm m
|
||||||
LEFT JOIN LATERAL jsonb_array_elements(m.regex->'where') w(v) ON TRUE
|
LEFT JOIN LATERAL jsonb_array_elements(m.regex->'regex'->'where') w(v) ON TRUE
|
||||||
INNER JOIN new_table t ON
|
INNER JOIN new_table t ON
|
||||||
t.srce = m.srce AND
|
t.srce = m.srce AND
|
||||||
t.rec @> w.v
|
t.rec @> w.v
|
||||||
LEFT JOIN LATERAL jsonb_array_elements(m.regex->'defn') WITH ORDINALITY e(v, rn) ON true
|
LEFT JOIN LATERAL jsonb_array_elements(m.regex->'regex'->'defn') WITH ORDINALITY e(v, rn) ON true
|
||||||
LEFT JOIN LATERAL regexp_matches(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text,COALESCE(e.v ->> 'flag','')) WITH ORDINALITY mt(mt, rn) ON
|
LEFT JOIN LATERAL regexp_matches(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text,COALESCE(e.v ->> 'flag','')) WITH ORDINALITY mt(mt, rn) ON
|
||||||
m.regex->>'function' = 'extract'
|
m.regex->'regex'->>'function' = 'extract'
|
||||||
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->'regex'->>'function' = 'replace'
|
||||||
ORDER BY
|
ORDER BY
|
||||||
t.id DESC,
|
t.id DESC,
|
||||||
m.target,
|
m.target,
|
||||||
@ -931,6 +938,7 @@ CREATE OR REPLACE FUNCTION tps.trans_insert_map() RETURNS TRIGGER AS $f$
|
|||||||
WHERE
|
WHERE
|
||||||
t.id = a.id;
|
t.id = a.id;
|
||||||
|
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END;
|
END;
|
||||||
|
Loading…
Reference in New Issue
Block a user