How to convert PostgreSQL 9.4's jsonb type to float

前端 未结 7 685
误落风尘
误落风尘 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条回答
  •  旧时难觅i
    2020-12-14 15:05

    When creating a view I used CAST:

    create view mydb.myview as
                select id,
                config->>'version' as version,
                config->>'state' as state,
                config->>'name' as name,
                config->>'internal-name' as internal_name,
                config->>'namespace' as namespace,         
                create_date,
                update_date,
                CAST(config ->> 'version' as double precision) as version_number
                from mydb.mytbl;
    

提交回复
热议问题