Skip to content

toDate(nullif('', '')), toDateTime(nullif('', '')) throws Parsing error #7673

@dmlogv

Description

@dmlogv

Describe the bug or unexpected behaviour

When casting nullif('', '') to Date/DateTime types using toDate()/toDateTime() ClickHouse returns exceptions:

SQL Error [38]: ClickHouse exception, code: 38, host: *, port: *; Code: 38, e.displayText() = DB::Exception: Cannot parse date: value is too short: Cannot parse Date from String (version 19.15.3.6)

SQL Error [41]: ClickHouse exception, code: 41, host: *, port: *; Code: 41, e.displayText() = DB::Exception: Cannot parse datetime: Cannot parse DateTime from String (version 19.15.3.6)

How to reproduce

Some expected results:

select
    toDateTime(NULL)


toDateTime(NULL)
----------------
[NULL]          
select
    toDateTime('')


SQL Error [41]: ClickHouse exception, code: 41, host: *, port: *; Code: 41, e.displayText() = DB::Exception: Cannot parse datetime: Cannot parse DateTime from String (version 19.15.3.6)
select
    nullif('', '')


nullif('', '')
--------------
[NULL]        
select
    toDateTime(nullif(1, 1))


toDateTime(nullif(1, 1))
------------------------
                  [NULL]
select
    toDateTimeOrNull(nullif('', ''))


toDateTimeOrNull(nullif('', ''))
--------------------------------
                          [NULL]

Unexpected behavior:

select
    toDateTime(nullif('', ''))


SQL Error [41]: ClickHouse exception, code: 41, host: *, port: *; Code: 41, e.displayText() = DB::Exception: Cannot parse datetime: Cannot parse DateTime from String (version 19.15.3.6)
select
    toDate(nullif('', ''))


SQL Error [38]: ClickHouse exception, code: 38, host: *, port: *; Code: 38, e.displayText() = DB::Exception: Cannot parse date: value is too short: Cannot parse Date from String (version 19.15.3.6)

Expected behavior

select
    toDateTime(nullif('', ''))


toDateTime(nullif('', ''))
--------------------------------
                          [NULL]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed user-visible misbehaviour in official releasecomp-datatype-wrapperType modifiers/wrappers (Nullable, LowCardinality, etc.).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions