【问题标题】:How to add custom default value to Nullable type when creating table in clickhouse?在 clickhouse 中创建表时如何将自定义默认值添加到 Nullable 类型?
【发布时间】:2021-11-09 12:50:06
【问题描述】:

我希望能够为特定行插入空值,而不是默认情况下 例如: 我希望能够为年龄插入空值,但如果未指定,则默认值为 10。

create table mytable
        (
            age Int null default 10,
            name String
            
        ) ENGINE = MergeTree()
        ORDER BY name

结果

Code: 62, e.displayText() = DB::Exception: Syntax error: failed at position 88 ('default') (line 3, col 26): default 10,
            name String
            
        ) ENGINE = MergeTree()
        ORDER BY name. Expected one of: CODEC, TTL, ClosingRoundBracket, Comma, COMMENT, token (version 21.8.10.19 (official build))

documentation 说: NULL is the default value for any Nullable type, unless specified otherwise in the ClickHouse server configuration.

我想我必须在这个page 上找到正确的设置,否则我误解了默认值和 Nullable 类型之间的关系......

【问题讨论】:

    标签: clickhouse


    【解决方案1】:

    ClickHouse 有一个特殊的语法Nullable( <type> ) --> age Nullable(Int)

    create table mytable
            (
                age Nullable(Int) default 10,
                name String
                
            ) ENGINE = MergeTree()
            ORDER BY name
    

    【讨论】:

    • 谢谢你这有正确的行为。我以为Nullable(Int)Int NULL是一样的...
    猜你喜欢
    • 2018-03-30
    • 1970-01-01
    • 1970-01-01
    • 2011-08-14
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多