1. Home
  2. Knowledge Base
  3. ChistaDATA
  4. Map Data Type in ClickHouse
  1. Home
  2. Knowledge Base
  3. ClickHouse Cloud
  4. Map Data Type in ClickHouse
  1. Home
  2. Knowledge Base
  3. ClickHouse DBA
  4. Map Data Type in ClickHouse

Map Data Type in ClickHouse

Map data type in ClickHouse is used to store key-value pairs in table columns. A key-value pair consists of two data elements that are related. Let us look at an example for creating a table with Map data type, inserting data into the table, and accessing the data.

CREATE TABLE map_example
(
map_column Map(String, Int32),
ID UInt32
) 
ENGINE=Log;

We can use the INSERT statement to insert values.

INSERT INTO map_example VALUES
({'Apple':1}, 1),
({'Banana':2}, 2);

To retrieve the values from the map column, we can use column_name[‘key’] syntax.

SELECT map_column['Apple'] FROM map_example;

We can use the map() function to convert key value pairs in to map data type.

SELECT map('key1', 1, 'key2', 2) as map_datatype;

 

References

https://clickhouse.com/docs/en/sql-reference/data-types/map

https://clickhouse.com/docs/en/sql-reference/functions/tuple-map-functions#map

Was this article helpful?

Related Articles

CHISTADATA IS COMMITTED TO OPEN SOURCE SOFTWARE AND BUILDING HIGH PERFORMANCE COLUMNSTORES

In the spirit of freedom, independence and innovation. ChistaDATA Corporation is not affiliated with ClickHouse Corporation 

Contents

Need Support?

Can't find the answer you're looking for?
Contact Support

ChistaDATA Inc. Knowledge base is licensed under the Apache License, Version 2.0 (the “License”)

Copyright 2022 ChistaDATA Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.