Skip to content
Advertisement

How to convert PostgreSQL 9.4’s jsonb type to float

I’m trying the following query:

(The +1.0 is just there to force conversion to float. My actual queries are far more complex, this query is just a test case for the problem.)

I get the error:

If I add in explicit casting:

the error becomes:

I understand that most jsonb values cannot be cast into floats, but in this case I know that the lats are all JSON numbers.

Is there a function which casts jsonb values to floats (or return NULLs for the uncastable)?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement