Re: Casting json (or jsonb) to real - Mailing list pgsql-admin

From Wells Oliver
Subject Re: Casting json (or jsonb) to real
Date
Msg-id CAOC+FBU6E394M6DGerpQD1Cv4t=te4tg6aCXTRWyeZ=RoHGM=g@mail.gmail.com
Whole thread Raw
In response to Re: Casting json (or jsonb) to real  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-admin
Thanks, yeah, a lot of this stored by json.dumps(v) in python, so this will allow me to update the column...

On Tue, May 31, 2022 at 6:18 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Wells Oliver <wells.oliver@gmail.com> writes:
> Well, it's because the representation of the value is getting double
> quoted, so it's
> select '"1.453"'::real, which yields ERROR:  cannot cast jsonb string to
> type real.

Oh ... that perhaps wasn't a great choice.  But it looks like you could
pretend the jsonb is a 1-element array, and do

regression=# select ('"1.4531"'::jsonb->>0)::real;
 float4
--------
 1.4531
(1 row)

                        regards, tom lane


--

pgsql-admin by date:

Previous
From: jian xu
Date:
Subject: RE: how to calibrate the cost model parameters
Next
From: Ron
Date:
Subject: Re: how to calibrate the cost model parameters