Should we support casting between ARRAYs and JSON(B)? - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Should we support casting between ARRAYs and JSON(B)?
Date
Msg-id CAJ7c6TP8eTH=LY2Juos2aaxEu0qrU4aQ5SQYhv6ukPh__gn6pQ@mail.gmail.com
Whole thread Raw
Responses Re: Should we support casting between ARRAYs and JSON(B)?
List pgsql-hackers
Hi hackers,

While reviewing another patch [1] I came to an idea to try something stupid:

=# select '{1,2,3}' :: int[];
  int4
---------
 {1,2,3}
=# select '{1,2,3}' :: int[] :: jsonb[];
ERROR:  cannot cast type integer[] to jsonb[]

=# select '[1,2,3]' :: jsonb;
   jsonb
-----------
 [1, 2, 3]
=# select '[1,2,3]' :: jsonb :: int[];
ERROR:  cannot cast type jsonb to integer[]

Does anyone believe that this should work and/or would be convenient
if it worked? I can imagine cases when one would like to use array_*
functions for JSON(B) although personally I didn't encounter such a
case (yet?).

Thoughts?

[1]: https://postgr.es/m/CAEG8a3J41a4dpw_-F94fF-JPRXYxw-GfsgoGotKcjs9LVfEEvw%40mail.gmail.com

-- 
Best regards,
Aleksander Alekseev



pgsql-hackers by date:

Previous
From: Jelte Fennema-Nio
Date:
Subject: Re: protocol-level wait-for-LSN
Next
From: Jelte Fennema-Nio
Date:
Subject: Re: protocol-level wait-for-LSN