From a5baf90bd6486808d644c5b21d9c1ebeff9050a9 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 30 May 2018 09:48:19 -0400 Subject: [PATCH] accomodate multiple map defintions at once in an array --- deploy/setup.sql | 22 ++++++++++++---------- interface/map_def/srce_map_def_set.sql | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/deploy/setup.sql b/deploy/setup.sql index dc6d3b3..dc55258 100644 --- a/deploy/setup.sql +++ b/deploy/setup.sql @@ -280,27 +280,29 @@ BEGIN tps.map_rm (srce, target, regex, seq, hist) SELECT --data source - _defn->>'srce' + ae.r->>'srce' --map name - ,_defn->>'name' + ,ae.r->>'name' --map definition - ,_defn->'regex' + ,ae.r->'regex' --map aggregation sequence - ,(_defn->>'sequence')::INTEGER + ,(ae.r->>'sequence')::INTEGER --history definition ,jsonb_build_object( - 'hist_defn',_defn + 'hist_defn',ae.r ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ) || '[]'::jsonb + FROM + jsonb_array_elements(_defn) ae(r) ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET - srce = _defn->>'srce' - ,target = _defn->>'name' - ,regex = _defn->'regex' - ,seq = (_defn->>'sequence')::INTEGER + srce = excluded.srce + ,target = excluded.target + ,regex = excluded.regex + ,seq = excluded.seq ,hist = --the new definition going to position -0- jsonb_build_object( - 'hist_defn',_defn + 'hist_defn',excluded.regex ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ) --the previous definition, set upper bound of effective range which was previously null diff --git a/interface/map_def/srce_map_def_set.sql b/interface/map_def/srce_map_def_set.sql index 20d26cf..c69abe4 100644 --- a/interface/map_def/srce_map_def_set.sql +++ b/interface/map_def/srce_map_def_set.sql @@ -16,27 +16,29 @@ BEGIN tps.map_rm (srce, target, regex, seq, hist) SELECT --data source - _defn->>'srce' + ae.r->>'srce' --map name - ,_defn->>'name' + ,ae.r->>'name' --map definition - ,_defn->'regex' + ,ae.r->'regex' --map aggregation sequence - ,(_defn->>'sequence')::INTEGER + ,(ae.r->>'sequence')::INTEGER --history definition ,jsonb_build_object( - 'hist_defn',_defn + 'hist_defn',ae.r ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ) || '[]'::jsonb + FROM + jsonb_array_elements(_defn) ae(r) ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET - srce = _defn->>'srce' - ,target = _defn->>'name' - ,regex = _defn->'regex' - ,seq = (_defn->>'sequence')::INTEGER + srce = excluded.srce + ,target = excluded.target + ,regex = excluded.regex + ,seq = excluded.seq ,hist = --the new definition going to position -0- jsonb_build_object( - 'hist_defn',_defn + 'hist_defn',excluded.regex ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ) --the previous definition, set upper bound of effective range which was previously null