Re: [GENERAL] JSON to INT[] or other custom type - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: [GENERAL] JSON to INT[] or other custom type
Date
Msg-id 20170612012213.GA31918@wolff.to
Whole thread Raw
In response to [GENERAL] JSON to INT[] or other custom type  (Rory Campbell-Lange <rory@campbell-lange.net>)
Responses Re: [GENERAL] JSON to INT[] or other custom type  (Rory Campbell-Lange <rory@campbell-lange.net>)
List pgsql-general
On Sun, Jun 11, 2017 at 22:35:14 +0100,
  Rory Campbell-Lange <rory@campbell-lange.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)



pgsql-general by date:

Previous
From: Andrew Kerber
Date:
Subject: Re: [GENERAL] Huge Pages - setting the right value
Next
From: Alvaro Herrera
Date:
Subject: Re: [GENERAL] Unsubscription