accomodate multiple map defintions at once in an array

This commit is contained in:
Paul Trowbridge 2018-05-30 09:48:19 -04:00
parent 286e2bfc60
commit a5baf90bd6
2 changed files with 24 additions and 20 deletions

View File

@ -280,27 +280,29 @@ BEGIN
tps.map_rm (srce, target, regex, seq, hist) tps.map_rm (srce, target, regex, seq, hist)
SELECT SELECT
--data source --data source
_defn->>'srce' ae.r->>'srce'
--map name --map name
,_defn->>'name' ,ae.r->>'name'
--map definition --map definition
,_defn->'regex' ,ae.r->'regex'
--map aggregation sequence --map aggregation sequence
,(_defn->>'sequence')::INTEGER ,(ae.r->>'sequence')::INTEGER
--history definition --history definition
,jsonb_build_object( ,jsonb_build_object(
'hist_defn',_defn 'hist_defn',ae.r
,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz)
) || '[]'::jsonb ) || '[]'::jsonb
FROM
jsonb_array_elements(_defn) ae(r)
ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET
srce = _defn->>'srce' srce = excluded.srce
,target = _defn->>'name' ,target = excluded.target
,regex = _defn->'regex' ,regex = excluded.regex
,seq = (_defn->>'sequence')::INTEGER ,seq = excluded.seq
,hist = ,hist =
--the new definition going to position -0- --the new definition going to position -0-
jsonb_build_object( jsonb_build_object(
'hist_defn',_defn 'hist_defn',excluded.regex
,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz)
) )
--the previous definition, set upper bound of effective range which was previously null --the previous definition, set upper bound of effective range which was previously null

View File

@ -16,27 +16,29 @@ BEGIN
tps.map_rm (srce, target, regex, seq, hist) tps.map_rm (srce, target, regex, seq, hist)
SELECT SELECT
--data source --data source
_defn->>'srce' ae.r->>'srce'
--map name --map name
,_defn->>'name' ,ae.r->>'name'
--map definition --map definition
,_defn->'regex' ,ae.r->'regex'
--map aggregation sequence --map aggregation sequence
,(_defn->>'sequence')::INTEGER ,(ae.r->>'sequence')::INTEGER
--history definition --history definition
,jsonb_build_object( ,jsonb_build_object(
'hist_defn',_defn 'hist_defn',ae.r
,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz)
) || '[]'::jsonb ) || '[]'::jsonb
FROM
jsonb_array_elements(_defn) ae(r)
ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET
srce = _defn->>'srce' srce = excluded.srce
,target = _defn->>'name' ,target = excluded.target
,regex = _defn->'regex' ,regex = excluded.regex
,seq = (_defn->>'sequence')::INTEGER ,seq = excluded.seq
,hist = ,hist =
--the new definition going to position -0- --the new definition going to position -0-
jsonb_build_object( jsonb_build_object(
'hist_defn',_defn 'hist_defn',excluded.regex
,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz)
) )
--the previous definition, set upper bound of effective range which was previously null --the previous definition, set upper bound of effective range which was previously null