Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwD0F-0002JP-Hv for pgsql-admin@arkaria.postgresql.org; Wed, 01 Jun 2022 01:18:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nwD0C-0001u0-NR for pgsql-admin@arkaria.postgresql.org; Wed, 01 Jun 2022 01:18:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwD0C-0001tq-7s for pgsql-admin@lists.postgresql.org; Wed, 01 Jun 2022 01:18:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwD07-0004nL-EL for pgsql-admin@postgresql.org; Wed, 01 Jun 2022 01:18:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2511II7x383083; Tue, 31 May 2022 21:18:18 -0400 From: Tom Lane To: Wells Oliver cc: pgsql-admin Subject: Re: Casting json (or jsonb) to real In-reply-to: References: <378261.1654044651@sss.pgh.pa.us> Comments: In-reply-to Wells Oliver message dated "Tue, 31 May 2022 18:08:54 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <383081.1654046298.1@sss.pgh.pa.us> Date: Tue, 31 May 2022 21:18:18 -0400 Message-ID: <383082.1654046298@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Wells Oliver 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