我被以下明显的矛盾弄糊涂了:
select json_extract_scalar('{"json_array":[{"array_field":"1"}]}',
'$.json_array') is null,
json_extract_scalar('{"json_array":[{"array_field":"1"}]}',
'$.json_array[0]') is null,
json_extract_scalar('{"json_array":[{"array_field":"1"}]}',
'$.json_array[0].array_field') is null结果:
true true false为什么json_array是NULL,但是当进一步挖掘的时候,它会突然恢复为非空的?
发布于 2018-10-29 08:08:07
这是因为您使用的是json_extract_scalar而不是json_extract。如果json路径的目标不是标量,则json_extract_scalar返回标量(不是数组或对象之类的组合)或NULL。
比较这些表达式。区别是使用json_extract_scalar和其他json_extract
presto> select json_extract_scalar('{"json_array":[{"array_field":"1"}]}', '$.json_array'),
-> json_extract('{"json_array":[{"array_field":"1"}]}', '$.json_array');
_col0 | _col1
-------+-----------------------
NULL | [{"array_field":"1"}]
(1 row)https://stackoverflow.com/questions/53038338
复制相似问题