How to convert PostgreSQL 9.4's jsonb type to float

前端 未结 7 668
误落风尘
误落风尘 2020-12-14 14:36

I\'m trying the following query:

SELECT (json_data->\'position\'->\'lat\') + 1.0 AS lat FROM updates LIMIT 5;

(The +1.0 is just there

7条回答
  •  春和景丽
    2020-12-14 14:51

    There are two operations to get value from JSON. The first one -> will return JSON. The second one ->> will return text.

    Details: JSON Functions and Operators

    Try

    SELECT (json_data->'position'->>'lat')::float + 1.0 AS lat
    FROM updates
    LIMIT 5
    

提交回复
热议问题