From: | Marcos Pegoraro <marcos(at)f10(dot)com(dot)br> |
---|---|
To: | Aleksander Alekseev <aleksander(at)timescale(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Should we support casting between ARRAYs and JSON(B)? |
Date: | 2024-10-28 17:29:44 |
Message-ID: | CAB-JLwbL45nMSA+xZkEac9+BGwyfbBeittQcnU0GKPD6DbShOg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Em seg., 28 de out. de 2024 às 14:06, Aleksander Alekseev <
aleksander(at)timescale(dot)com> escreveu:
> =# select '[1,2,3]' :: jsonb :: int[];
>
I think would be useful, cast int[] to json is not hard
select to_json('{1,5,9,12}'::int[]);
but json array to int[] is not that easy.
select js,
js->'items',
translate(js->>'items','[]','{}')::int[],
5 = any(translate(js->>'items','[]','{}')::int[])
--This one would be cool, doesn't need translate or any other trick
--5 = any(js->'items'::int[])
from (select jsonb_build_object('items','{1,5,9,12}'::int[])) x(js);
So, if you cast one way, you can do both ways.
regards
Marcos
From | Date | Subject | |
---|---|---|---|
Next Message | Bernd Helmle | 2024-10-28 17:44:10 | Re: [PATCH] Add sortsupport for range types and btree_gist |
Previous Message | Jelte Fennema-Nio | 2024-10-28 17:07:57 | Re: protocol-level wait-for-LSN |