Search code examples
clickhouse

What is the error when creating a table in the clickhouse = SummingMergeTree engine?


I'm trying to create a table in clickhouse directly from the documentation. https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/summingmergetree/#usage-example

[2023-03-10 11:11:43] Code: 223. DB::Exception: [value] is not an identifier. (UNEXPECTED_AST_STRUCTURE) (version 23.2.3.17 (official build)) [2023-03-10 11:11:43] , server ClickHouseNode [uri=http://localhost:51584/default, options={custom_http_params=session_id=DataGrip_944476ca-188b-451f-ba27-d2265ff05354}]@-1702792093

trying to create a table in clickhouse directly from the documentation.


Solution

  • Here's a simple example. Rows with the same primary key collapse into one row, and numeric columns are automatically summed together. (For non-numeric columns, a random value is picked).

    You definitely don't want the square brackets...

    CREATE TABLE smt (
        id UInt32,
        x UInt32,
        y UInt32,
        z String
    )
    ENGINE = SummingMergeTree
    PRIMARY KEY id;
    
    INSERT INTO smt VALUES 
       (1, 10, 100, 'Hello'),
       (1, 20, 200, 'Goodbye'),
       (2, 30, 300, 'Hi'),
       (2, 40, 400, 'Bye');
    
    SELECT *
    FROM smt
    
    Query id: dad88e93-5d4a-4a8c-8342-46e9d93cf02a
    
    ┌─id─┬──x─┬───y─┬─z─────┐
    │  1 │ 30 │ 300 │ Hello │
    │  2 │ 70 │ 700 │ Hi    │
    └────┴────┴─────┴───────┘
    
    2 rows in set. Elapsed: 0.007 sec.