Accessing nested maps

162 views
Skip to first unread message

Karla Rehn

unread,
Sep 23, 2022, 1:53:37 PM9/23/22
to ClickHouse
Hi! I'm using Clickhouse's wonderful Map-feature for a column. 

The data structure for the column is Map<String, Map<String, String>>, so
one element in a row could look like

{'outer_key1': {'inner_key1' : 'value1', 'inner_key2': 'value2'}, 'outer_key2':{'inner_key1': 'value3', 'inner_key3': 'value4'}}

 While I can get rows just fine with

select * from table where columnname['outer_key1'] = '{'inner_key1': 'value1', 'inner_key2': 'value2'}'

I'd like to be able to access the inner values directly, with something like

select * from table where columnname['outer_key1']['inner_key1'] = 'value1'

I have googled some, but not found a way to do this. Is what I'm trying to
do possible? What is the correct syntax for it?

Karla Rehn

unread,
Sep 26, 2022, 3:03:20 AM9/26/22
to ClickHouse
I was correct to begin with, not sure why it didn't work.

select * from table where columnname['outer_key1']['inner_key1'] = 'value1' does work.

CatsYLing

unread,
Sep 26, 2022, 11:26:05 PM9/26/22
to ClickHouse

Try this
select * from table where columnname['outer_key1'] = map('inner_key1', 'value1', 'inner_key2', 'value2');
Reply all
Reply to author
Forward
0 new messages