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)