Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clickhouse, column values to array

Tags:

sql

clickhouse

I want to make a query then turn the values for each of it's columns into arrays, I've tried finding a way to do this, but until now it has alluded me.

The query is a simple select:

SELECT a,b,c FROM X

Instead of the usual result of say (in the default format):

val_a_1, val_b_1, val_c_1

----------------

val_a_2, val_b_2, val_c_2

-----------------

val_a_3, val_b_3, val_c_3

I want to get an array for each columns, namely:

[val_a_1, val_a_2, val_a_3], [val_b_1, val_b_2, val_b_3] , [val_c_1, val_c_2, val_c_3]

Is this at all possible ?

like image 970
George Avatar asked Dec 14 '22 16:12

George


1 Answers

Nevermind, this can easily be done with groupArray as:

SELECT groupArray(a), groupArray(b), groupArray(c) FROM X

It completely slipped my mind and google didn't help... leaving this here in case there's a better option or anyone stumbles upon it when searching.

like image 150
George Avatar answered Dec 17 '22 23:12

George