You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 22, 2025. It is now read-only.
Oleg V. Kozlyuk edited this page Feb 11, 2023
·
5 revisions
ClickHouse's support for Nested columns has limitations - namely, Nested columns cannot be SELECTed/INSERTed directly. However, they can be worked with using array semantics, and ClickHouse.Client supports it.
For example, given table with following structure:
CREATETABLEIF NOT EXISTS test.nested (id UInt32, params Nested (param_id UInt8, param_val String)) ENGINE = Memory
For query purposes, ClickHouse will treat it as table with 3 fields:
id: UInt32,
params.param_id: Array(UInt8)
params.param_val Array(String)
Given that, we can use ClickHouseBulkCopy to insert the data into this table in following way:
usingvarbulkCopy=newClickHouseBulkCopy(connection){DestinationTableName="test.nested"};// Note again that technically the table has 2 columns, but we are preparing 3-column rowsvarrow1=newobject[]{1,new[]{1,2,3},new[]{"v1","v2","v3"}};varrow2=newobject[]{2,new[]{4,5,6},new[]{"v4","v5","v6"}};awaitbulkCopy.WriteToServerAsync(new[]{row1,row2},CancellationToken.None);
And we can get the results back in same way:
usingvarreader=awaitconnection.ExecuteReaderAsync("SELECT * FROM test.nested ORDER BY id ASC");varvalues=Enumerable.Range(0,reader.FieldCount).Select(reader.GetValue).ToArray();// First rowAssert.AreEqual(1,values[0]);// `id` columnCollectionAssert.AreEquivalent(new[]{1,2,3},values[1]asIEnumerable);// `params.param_id` pseudo-columnCollectionAssert.AreEquivalent(new[]{"v1","v2","v3"},values[2]asIEnumerable);// `params.param_val` pseudo-column