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 1paImK-00078h-Cy for pgsql-admin@arkaria.postgresql.org; Thu, 09 Mar 2023 16:06:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1paImI-0007M4-Vt for pgsql-admin@arkaria.postgresql.org; Thu, 09 Mar 2023 16:06:02 +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 1paImI-0007Lv-LH for pgsql-admin@lists.postgresql.org; Thu, 09 Mar 2023 16:06:02 +0000 Received: from mout-u-107.mailbox.org ([80.241.59.207]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1paImG-0003yi-5g for pgsql-admin@postgresql.org; Thu, 09 Mar 2023 16:06:02 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4PXYv84DgPz9sQL; Thu, 9 Mar 2023 17:05:56 +0100 (CET) Date: Thu, 9 Mar 2023 17:05:56 +0100 (CET) From: Erik Wienhold To: Wells Oliver , pgsql-admin Message-ID: <84644851.192870.1678377956057@office.mailbox.org> In-Reply-To: References: Subject: Re: Malformed array literal in goin from jsonb to real[] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 09/03/2023 16:19 CET Wells Oliver wrote: > > This value exists in my jsonb column: > > [[-0.7452975, -0.21457797, 0.631259], [0.66549873, -0.2969812, 0.6847727]= , [0.04053491, 0.9304614, 0.3641407]] > > Which obviously blows up when doing (jsonb->>col)::real[] with malformed > array literal. > > Is there a convenient=C2=A0function to do this casting or do I need to do= somes > awful string munging? Use jsonb_populate_record with a custom type: =09create type myrec as (col real[][]); =09 =09select * from jsonb_populate_record(null::myrec, '{"col":[[0,1],[2,3]]}'= ); =09 =09 col =09--------------- =09 {{0,1},{2,3}} =09(1 row) -- Erik