try modifying the mult map set function
This commit is contained in:
parent
f9aa2a31a6
commit
e122c4987b
@ -10,65 +10,64 @@ DECLARE
|
|||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
tps.map_rm (srce, target, regex, seq, hist)
|
tps.map_rm (srce, target, regex, seq, hist)
|
||||||
SELECT
|
SELECT
|
||||||
--data source
|
--data source
|
||||||
ae.r->>'srce'
|
ae.r->>'srce'
|
||||||
--map name
|
--map name
|
||||||
,ae.r->>'name'
|
,ae.r->>'name'
|
||||||
--map definition
|
--map definition
|
||||||
,ae.r
|
,ae.r
|
||||||
--map aggregation sequence
|
--map aggregation sequence
|
||||||
,(ae.r->>'sequence')::INTEGER
|
,(ae.r->>'sequence')::INTEGER
|
||||||
--history definition
|
--history definition
|
||||||
,jsonb_build_object(
|
,jsonb_build_object(
|
||||||
'hist_defn',ae.r
|
'hist_defn',ae.r
|
||||||
,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz)
|
,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz)
|
||||||
) || '[]'::jsonb
|
) || '[]'::jsonb
|
||||||
FROM
|
FROM
|
||||||
jsonb_array_elements(_defn) ae(r)
|
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 = excluded.srce
|
srce = excluded.srce
|
||||||
,target = excluded.target
|
,target = excluded.target
|
||||||
,regex = excluded.regex
|
,regex = excluded.regex
|
||||||
,seq = excluded.seq
|
,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',excluded.regex
|
'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
|
||||||
|| jsonb_set(
|
|| jsonb_set(
|
||||||
map_rm.hist
|
map_rm.hist
|
||||||
,'{0,effective,1}'::text[]
|
,'{0,effective,1}'::text[]
|
||||||
,to_jsonb(CURRENT_TIMESTAMP)
|
,to_jsonb(CURRENT_TIMESTAMP)
|
||||||
);
|
);
|
||||||
|
|
||||||
EXCEPTION WHEN OTHERS THEN
|
_message:= jsonb_build_object('status','complete','message','definition has been set');
|
||||||
|
|
||||||
GET STACKED DIAGNOSTICS
|
|
||||||
_MESSAGE_TEXT = MESSAGE_TEXT,
|
|
||||||
_PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL,
|
|
||||||
_PG_EXCEPTION_HINT = PG_EXCEPTION_HINT;
|
|
||||||
_message:=
|
|
||||||
($$
|
|
||||||
{
|
|
||||||
"status":"fail",
|
|
||||||
"message":"error setting definition"
|
|
||||||
}
|
|
||||||
$$::jsonb)
|
|
||||||
||jsonb_build_object('message_text',_MESSAGE_TEXT)
|
|
||||||
||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL);
|
|
||||||
return _message;
|
|
||||||
END;
|
|
||||||
|
|
||||||
_message:= jsonb_build_object('status','complete','message','definition has been set');
|
|
||||||
return _message;
|
return _message;
|
||||||
|
|
||||||
|
|
||||||
|
GET STACKED DIAGNOSTICS
|
||||||
|
_MESSAGE_TEXT = MESSAGE_TEXT,
|
||||||
|
_PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL,
|
||||||
|
_PG_EXCEPTION_HINT = PG_EXCEPTION_HINT;
|
||||||
|
_message:=
|
||||||
|
($$
|
||||||
|
{
|
||||||
|
"status":"fail",
|
||||||
|
"message":"error setting definition"
|
||||||
|
}
|
||||||
|
$$::jsonb)
|
||||||
|
||jsonb_build_object('message_text',_MESSAGE_TEXT)
|
||||||
|
||jsonb_build_object('pg_exception_detail',_PG_EXCEPTION_DETAIL);
|
||||||
|
return _message;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$f$
|
$f$
|
||||||
language plpgsql
|
language plpgsql
|
Loading…
Reference in New Issue
Block a user