Re: Casting json (or jsonb) to real

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Casting json (or jsonb) to real
Date: 2022-06-01 01:18:18
Message-ID: 383082.1654046298@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Wells Oliver <wells(dot)oliver(at)gmail(dot)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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message jian xu 2022-06-01 02:20:59 RE: how to calibrate the cost model parameters
Previous Message Wells Oliver 2022-06-01 01:14:28 Re: Casting json (or jsonb) to real