Skip to content

Clickhouse does not validate DEFAULT value on MODIFY COLUMN for type compability #15854

@MasterGroosha

Description

@MasterGroosha

Describe the bug
Here's my table:

CREATE TABLE table2
(
        EventDate Date,
        Id Int32,
        Value Int32
)
Engine = MergeTree()
PARTITION BY toYYYYMM(EventDate)
ORDER BY Id;

Modify default value (intentionally wrong):

>>> alter table table2 modify column Value default 'some_string';

ALTER TABLE table2
    MODIFY COLUMN `Value` DEFAULT 'some_string'

Ok.

0 rows in set. Elapsed: 0.007 sec. 

Now you obviously cannot insert anything to this table, because:

>>> insert into table2 (EventDate, Id) values (1234567890, 2)

INSERT INTO table2 (EventDate, Id) VALUES

Received exception from server (version 20.9.3):
Code: 6. DB::Exception: Received from localhost:9000. DB::Exception: Cannot parse string 'some_string' as Int32: syntax error at begin of string. Note: there are toInt32OrZero and toInt32OrNull functions, which returns zero/NULL instead of throwing exception.. 

1 rows in set. Elapsed: 0.002 sec. 

How to reproduce

  • Which ClickHouse server version to use: 20.9.3
  • Which interface to use, if matters: I used standard CLI

Expected behavior
Currently ClickHouse doesn't check types compability while setting a DEFAULT value for a column. Maybe ClickHouse should validate DEFAULT values for type compability?

Metadata

Metadata

Assignees

Labels

bugConfirmed user-visible misbehaviour in official release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions