postgresql - 在 PostgreSQL JSON 中查找结果节点的路径
问题描述
我想执行 jsonpath 查询jsonb_path_query_all(..., '$.**.bar)
,例如
{
"foo": [
{ "xxx": 24 }
{ "bar": 42 }
]
}
但不是只得到结果[42]
,我想找到结果的所有路径,所以在这种情况下它将是[ ["foo", 1 ] ]
. 有没有一种在 JSON 中查找值“位置”的有效方法?
在 JS jsonpath 中有类似jp.paths或jp.nodes的方法可以做到这一点。
编辑:遗憾的是 Postgres 不支持$..bar
JSONPath 的许多实现支持的符号:
# SELECT jsonb_path_query('{"foo":{"bar":42}}'::jsonb, '$..bar');
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: ...ECT jsonb_path_query('{"foo":{"bar":42}}'::jsonb, '$..bar');
解决方案
推荐阅读
- visual-studio - 如何将 .vsix 格式的 Visual Studio 主题转换为 .vsettings 以在 Visual Studio Mac 2019 上使用?
- ffmpeg - 如何在系统服务中设置 nVidia 视频比特率?
- ios - altbeacon-IOS,只有ibeacon没有被扫描
- c# - 有没有办法比较 C# 中字符串的确切值
- amazon-web-services - 如何从 CodeCommit 自动安装到 Raspberry Pi?
- node.js - Heroku pre-recieve hook 被拒绝,无法使用 MERN 堆栈将一些参考推送到 [app-url]
- python - get_attribute("title) 返回空字符串
- css - 将“float”转换为“flexbox”
- solidity - 如何从预言机获取价格并在另一个智能合约中保持最新?
- python - 为什么 Tensorflow 数据集生成会两次混洗数据?