Re: JSON to INT[] or other custom type

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Rory Campbell-Lange <rory(at)campbell-lange(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: JSON to INT[] or other custom type
Date: 2017-06-12 01:22:13
Message-ID: 20170612012213.GA31918@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Jun 11, 2017 at 22:35:14 +0100,
Rory Campbell-Lange <rory(at)campbell-lange(dot)net> wrote:
>
>I'm hoping, in the plpgsql function, to unfurl the supplied json into a
>custom type or at least an array of ints, and I can't work out how to do
>that.
>
> select * from json_array_elements_text('[[0, 1], [1, 2]]');
> value
> --------
> [0, 1]
> [1, 2]
> (2 rows)
>
>works fine, but I can't seem to turn those values into actual ints or
>anything else for that matter, apart from text via the
>json_array_elements_text() function.

Does this example help?

area=> select (a->>0)::int, (a->>1)::int from json_array_elements('[[0, 1], [1, 2]]') as s(a);
int4 | int4
------+------
0 | 1
1 | 2
(2 rows)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2017-06-12 01:46:59 Re: Unsubscription
Previous Message Andrew Kerber 2017-06-11 22:36:20 Re: Huge Pages - setting the right value