Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 通过变量路径访问JSONB元素_Postgresql_Concat_Jsonb - Fatal编程技术网

Postgresql 通过变量路径访问JSONB元素

Postgresql 通过变量路径访问JSONB元素,postgresql,concat,jsonb,Postgresql,Concat,Jsonb,我需要将两个json值合并为一个。 但是这些变量的位置是动态的,我从数据库中获取jsonb中的位置 所以我希望能做这样的事情: select '{"a": {"b": {"c": "d"}}}'::jsonb #> '{"a","b","c"}'; select value#>>'{"c"}' from jsonb_each(('{"a": {"b": {"c": "d"}}}'::jsonb#>'{"a"}')) where key = 'b'; 但我无法让它与变量

我需要将两个json值合并为一个。 但是这些变量的位置是动态的,我从数据库中获取jsonb中的位置

所以我希望能做这样的事情:

select '{"a": {"b": {"c": "d"}}}'::jsonb #> '{"a","b","c"}';
select value#>>'{"c"}' from jsonb_each(('{"a": {"b": {"c": "d"}}}'::jsonb#>'{"a"}')) where key = 'b';
但我无法让它与变量一起工作,因为我不知道该将路径转换为什么

select '{"a": {"b": {"c": "d"}}}'::jsonb #> ('{"a","' || variable_from_database || '","c"}')::dataTypeOfJsonbPath;
我还发现我可以使用如下查询:

select '{"a": {"b": {"c": "d"}}}'::jsonb #> '{"a","b","c"}';
select value#>>'{"c"}' from jsonb_each(('{"a": {"b": {"c": "d"}}}'::jsonb#>'{"a"}')) where key = 'b';
这将解决获取值的问题,但现在我需要在原始jsonb值中对它们进行压缩,而我目前不知道如何完成

jsonb_set('{"a": {"b": {"c": "d"}}}'::jsonb, ('{"a","' || value2FromDatabase || '", "c"}'),
                                          (value1 || value2)::jsonb, false);
由于同样的原因,上述方法失败了

列出jsonb_集合所需的参数告诉我,第二个参数应该是ARRAY类型,但我不知道如何将该字符串转换为一个数组,从而使其工作

有人能告诉我如何在一个jsonb对象中将一个值附加到另一个值,而这两个值的键都位于动态位置吗

select '{"a": {"b": {"c": "d"}}}'::jsonb #>> ('{"a","'||'b'||'","c"}')::text[];
这很有效,所以我需要转换为文本[]。 真管用

这很有效,所以我需要转换为文本[]。
真管用

将路径转换为类型
text[]


将路径强制转换为类型
text[]


我相信你是
[postgresql]+[json(b)]
组合:)+1最杰出的专家我相信你是
[postgresql]+[json(b)]
组合:)+1最杰出的专家