Cast json array to postgres array and preserve order of elements

From: otar shavadze <oshavadze(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Cast json array to postgres array and preserve order of elements
Date: 2020-05-10 12:21:35
Message-ID: CAG-jOyDBeXpiuztbB8RWnK6W5uEx1s_SJQ=wgu7c1AqAd33Fjg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

When I want t to convert json array into postgres array, I do:

with t(j) as(
> select '{"my_arr":[3,1,2]}'::json
> )
> SELECT ARRAY(SELECT json_array_elements_text(j->'my_arr')) from t

It works like a charm and I never noticed any problem, but I'm asking here
just to make sure, order of elements will be preserved always?
Is that guaranteed in above example, or not?

Thanks.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2020-05-10 12:25:23 Re: [PATCH] Incremental sort (was: PoC: Partial sort)
Previous Message Michael Paquier 2020-05-10 02:00:36 Re: Should smgrdounlink() be removed?