Re: Casting json (or jsonb) to real

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wells Oliver <wells.oliver@xxxxxxxxx> 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





[Index of Archives]     [Postgresql Home]     [Postgresql General]     [Postgresql Performance]     [Postgresql PHP]     [Postgresql Jobs]     [PHP Users]     [PHP Databases]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Forum]

  Powered by Linux