我正在运行postgresql 12,并试图使用jsonpath。
我想使用jsonb_path_query_first来获取数组的长度。我知道我可以做json_array_length,但我宁愿不做。
下面是我想要解决的问题。
select jsonb_path_query_first('{"a":3,"b":6,"s":[1,2,3,4,5], "d":{"v":4}}'::jsonb, '$.s.length()'::jsonpath);
ERROR: syntax error, unexpected '(', expecting end of file at or near "(" of jsonpath input
LINE 1: ...a":3,"b":6,"s":[1,2,3,4,5], "d":{"v":4}}'::jsonb, '$.s.lengt...postgresql 12中的jsonpath版本是否不支持这种类型的jsonpath功能。
发布于 2022-07-18 13:18:09
为此,可以使用.size()方法:
test# select
jsonb_path_query_first(
'{"a":3,"b":6,"s":[1,2,3,4,5], "d":{"v":4}}'::jsonb,
'$.s.size()'::jsonpath
);
jsonb_path_query_first
════════════════════════
5
(1 row)https://stackoverflow.com/questions/73022521
复制相似问题