Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presto: cast an integer array to string?

I have the following table:

my_id, my_array
 1   , [5, 6, 3]
 2   , [1, 5]
 3.  , [6, 7, 5]

Would it be possible to do a cast such that the output table would be something like:

my_id, my_str
 1   , "5,6,3"
 2   , "1,5"
 3.  , "6,7,5"

Or if there is any way I could directly group by my_array would be fine too. Thanks!

like image 303
Edamame Avatar asked Jun 16 '26 06:06

Edamame


1 Answers

Use array_join function

select array_join(my_array,',') my_str

And of course you can group by array. This works:

select max(id) id , my_array
from
(select 1 id, array[5, 6, 3] as my_array) s
group by my_array
like image 127
leftjoin Avatar answered Jun 18 '26 20:06

leftjoin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!