postgres 中 jsonpath 表达式内的参数

问题描述 投票:0回答:1

如何在 PostgreSQL SQL 查询中使用 JSONPath 表达式中的参数?

我想查询这样的问题:

SELECT * FROM table WHERE jsondata @@ '$.pathto.array[*].** ? (@.someproperty == ":VALUE").anotherproperty != null';

我尝试过:

SELECT * FROM table WHERE jsondata @@ '$.pathto.array[*].** ? (@.someproperty == "1").anotherproperty != null';

此查询有效,但我无法将其与绑定参数(“1”)一起使用。

sql postgresql jsonpath json-path-expression
1个回答
0
投票

使用

jsonb_path_match(target jsonb, path jsonpath, vars jsonb)
并将变量作为
vars
文字传递到第三个参数
jsonb
中。

请参阅文档中的示例:demo

select jsonb_path_match('{"a":[1,2,3,4,5]}', 
                        'exists($.a[*] ? (@ >= $min && @ <= $max))', 
                        '{"min":2, "max":4}');
--true
© www.soinside.com 2019 - 2024. All rights reserved.