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 1nwCZd-0001IF-Bx for pgsql-admin@arkaria.postgresql.org; Wed, 01 Jun 2022 00:50:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nwCZc-0000zZ-5i for pgsql-admin@arkaria.postgresql.org; Wed, 01 Jun 2022 00:50:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwCZb-0000zP-RX for pgsql-admin@lists.postgresql.org; Wed, 01 Jun 2022 00:50:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwCZZ-0006g5-PN for pgsql-admin@postgresql.org; Wed, 01 Jun 2022 00:50:55 +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 2510opKM378262; Tue, 31 May 2022 20:50:51 -0400 From: Tom Lane To: Wells Oliver cc: pgsql-admin Subject: Re: Casting json (or jsonb) to real In-reply-to: References: Comments: In-reply-to Wells Oliver message dated "Tue, 31 May 2022 17:31:26 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <378260.1654044651.1@sss.pgh.pa.us> Date: Tue, 31 May 2022 20:50:51 -0400 Message-ID: <378261.1654044651@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Wells Oliver 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