pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Wells Oliver <wells.oliver@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Casting json (or jsonb) to real
Date: Tue, 31 May 2022 21:18:18 -0400
Message-ID: <383082.1654046298@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOC+FBVgADFvgpwTeSB=vU=Lv2ea_HvJZdZSZr5A7B=9d_p0Ww@mail.gmail.com>
References: <CAOC+FBW85OU9bRFC0ozNtiWFcGkMjCLv3fuVH8LSbiZ8qcX8_g@mail.gmail.com>
	<378261.1654044651@sss.pgh.pa.us>
	<CAOC+FBVgADFvgpwTeSB=vU=Lv2ea_HvJZdZSZr5A7B=9d_p0Ww@mail.gmail.com>

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





view thread (6+ messages)  latest in thread

Message-ID: <383082.1654046298@sss.pgh.pa.us>
Permalink:  ../383082.1654046298@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/383082.1654046298@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, wells.oliver@gmail.com
  Subject: Re: Casting json (or jsonb) to real
  In-Reply-To: <383082.1654046298@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox