Wells Oliver <wells.oliver@gmail.com> writes:
> When I know this value is a floating point value I would just like to cast
> SELECT value::real but you can't do that. You can do SELECT
> (jsonbcol->>'somekey')::real, but these columns just store a value.
Works for me, in v11 and up:
regression=# select '1.4531'::jsonb::real;
float4
--------
1.4531
(1 row)
In older versions you could do
regression=# select '1.4531'::jsonb::text::real;
float4
--------
1.4531
(1 row)
I fear that either one involves a conversion to text and back
under the hood :-(. Now, if you were casting to numeric,
that would be very cheap.
regards, tom lane