Re: Malformed array literal in goin from jsonb to real[]

From: Erik Wienhold <ewie(at)ewie(dot)name>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>, pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Malformed array literal in goin from jsonb to real[]
Date: 2023-03-09 16:05:56
Message-ID: 84644851.192870.1678377956057@office.mailbox.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

> On 09/03/2023 16:19 CET Wells Oliver <wells(dot)oliver(at)gmail(dot)com> 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 function to do this casting or do I need to do somes
> awful string munging?

Use jsonb_populate_record with a custom type:

create type myrec as (col real[][]);

select * from jsonb_populate_record(null::myrec, '{"col":[[0,1],[2,3]]}');

col
---------------
{{0,1},{2,3}}
(1 row)

--
Erik

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Erik Wienhold 2023-03-09 16:12:57 Re: Malformed array literal in goin from jsonb to real[]
Previous Message Wells Oliver 2023-03-09 15:19:59 Malformed array literal in goin from jsonb to real[]