postgresql - 查询 postgresql jsonb 列中的内部字段
问题描述
我有一个 jsonb 列,其结构如下:
{
.....other fields,
"a" : {
"b" : {
"c" : "some value",
....other fields
}
.....other fields
},
...other fields
}
我可以有这样的查询,属性是表 MyTable 中的列名:
SELECT * from
MyTable t
WHERE t.properties @> '{"a":{"b":{"c": "some value"}}}';
但是“c”之前的字段可能不同,即我们可以有:
{
.....other fields,
"m" : {
"n" : {
"c" : "some value",
....other fields
}
.....other fields
},
...other fields
}
如何针对这种情况修改我的查询?
解决方案
如果嵌套始终处于同一级别,则可以使用 JSON/Path 表达式:
select *
from the_table
where properties @@ '$.*.*.c == "some value"'
推荐阅读
- ms-access - MS Access 查询条件基于另一个查询中的特定字段
- raspberry-pi - 将整数转换为二进制以进行 SPI 传输
- android-studio - AndroidStudio 运行 Recorded Espresso 测试失败
- angular - RXJS:按队列请求 - ForkJoin
- r - 结合 ggplots 会为每个绘图显示完全相同的绘图图形
- python - python,torch,GAN,将张量解码为值
- javascript - 如何让我的 .js 文件读取其他文件的 HTML 变量,而不仅仅是一个?
- macos - 无法使用 brew 安装节点
- python-3.x - `gallery-dl` 在哪里加载它的配置?
- php - PHP Swoole协程,异步消息不异步