Search code examples
sqljsonprestojson-extracttrino

Extract negative integers from JSON


I am using the json_extract function in PrestoSQL, however, if the key-value pair appears with a negative integer in the value such as

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

json_extract(json, '$.foo') will return NULL but

json_extract(json, '$.bar') will return 12345

json_extract_scalar also produces the same.

What is the workaround for extracting negative integers in Presto?


Solution

  • It works as expected in current 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)