Return JSON array in query

659 views
Skip to first unread message

Jonatas Freitas

unread,
May 15, 2018, 5:31:00 PM5/15/18
to ClickHouse

Table structure
session_id String
details String (with JSON)


RAW data example
1;{"a": 2}
1;{"b": 2}
2;{"d": 2}
2;{"b": 2}


Expected result
1;[{"a": 2}, {"b": 2}]
2;[{"d": 2}, {"b": 2}]


Have any way?

Denis Zhuravlev

unread,
May 15, 2018, 6:01:23 PM5/15/18
to ClickHouse
select a, concat('[',arrayStringConcat(groupArray(x), ','),']')
from (
select 1 as a, '{"a": 2}' as x
union all
select 1 as a, '{"b": 2}' as x
) group by a

Check https://clickhouse.yandex/docs/en/formats/jsoneachrow/ maybe you will able to use clickhouse-client to render json from your data.
Reply all
Reply to author
Forward
0 new messages