首页 > 解决方案 > 从 JSON 中提取负整数

问题描述

json_extract在 PrestoSQL 中使用该函数,但是,如果键值对在值中出现负整数,例如

{"foo":-12345, "bar": 12345}

json_extract(json, '$.foo')将返回 NULL 但

json_extract(json, '$.bar')将返回 12345

json_extract_scalar也产生相同的结果。

在 Presto 中提取负整数的解决方法是什么?

标签: sqljsonprestojson-extracttrino

解决方案


它在当前master(Presto 320)中按预期工作:

presto:default> SELECT json_extract(JSON '{"foo":-12345, "bar": 12345}', '$.foo');
 _col0
--------
 -12345
(1 row)
presto:default> SELECT json_extract_scalar(JSON '{"foo":-12345, "bar": 12345}', '$.foo');
 _col0
--------
 -12345
(1 row)

推荐阅读