我有两个数组,如下所示,因为我连接了两个数组 -
Array1
中的 ST 键值被 ST
中的 Array2
键值中的值替换,
阵列1:
{"ST": ["Bin", "No", "Comp"], "OSS": ["Class"]}
数组2:
{"ST": ["Pro", "SU"]}"
预期输出:
{"ST": ["Bin", "No", "Comp","Pro", "SU"], "OSS": ["Class"]}
我如何实现这一目标?
WITH js AS (
SELECT
'{"ST": ["Bin", "No", "Comp"], "OSS": ["Class"]}'::jsonb AS js_data
)
SELECT
jsonb_set(js_data, '{ST}',
jsonb_path_query_array(js_data,
'($.ST[*])') || '["Pro", "SU"]'::jsonb)
FROM
js
;
jsonb_set
--------------------------------------------------------------
{"ST": ["Bin", "No", "Comp", "Pro", "SU"], "OSS": ["Class"]}