Skip to content

accurateCastOrDefault doesn't work with Array/Tuple/Map types #61982

Open

Description

@Avogar
avogar-dev :) select accurateCastOrDefault('', 'Array(UInt32)')

SELECT accurateCastOrDefault('', 'Array(UInt32)')

Query id: feeeb97c-acdb-4eba-a3e4-498f2c319873


Elapsed: 0.005 sec.

Received exception:
Code: 43. DB::Exception: Nested type Array(UInt32) cannot be inside Nullable type: While processing accurateCastOrDefault('', 'Array(UInt32)'). (ILLEGAL_TYPE_OF_ARGUMENT)

avogar-dev :) select accurateCastOrDefault('', 'Tuple(UInt32)')

SELECT accurateCastOrDefault('', 'Tuple(UInt32)')

Query id: 66fc4dec-75ca-42b4-afbf-fc5b33a1754d


Elapsed: 0.005 sec.

Received exception:
Code: 43. DB::Exception: Nested type Tuple(UInt32) cannot be inside Nullable type: While processing accurateCastOrDefault('', 'Tuple(UInt32)'). (ILLEGAL_TYPE_OF_ARGUMENT)

avogar-dev :) select accurateCastOrDefault('', 'Map(UInt32, UInt32)')

SELECT accurateCastOrDefault('', 'Map(UInt32, UInt32)')

Query id: d7435b7a-e967-4043-bc58-01785ea8a5c9


Elapsed: 0.005 sec.

Received exception:
Code: 43. DB::Exception: Nested type Map(UInt32, UInt32) cannot be inside Nullable type: While processing accurateCastOrDefault('', 'Map(UInt32, UInt32)'). (ILLEGAL_TYPE_OF_ARGUMENT)

Activity

  1. added
    unexpected behaviour
    on Mar 27, 2024
  2. Avogar commented on Mar 27, 2024

    @Avogar
    MemberAuthor

    The problem is - accurateCastOrDefault is implemented by converting type to Nullable and using accurateCastOrNull. We should reimplement it.

  3. CurtizJ commented on Mar 27, 2024

    @CurtizJ
    Member

    Previously it was closed with st-wontfix: #31440

  4. Avogar commented on Mar 27, 2024

    @Avogar
    MemberAuthor

    From the first glance it sounds not so difficult: add CastType::accurateCastOrDefault and process it in FunctionsConversion almost in the same way as CastType::accurateCastOrNull.

  5. tobia commented on Jun 17, 2024

    @tobia

    The fact that both are unavailable means that one cannot check whether a cast would work before doing it.

    Is there any other way to test if a value can be casted to another, when both accurateCastOrDefault and accurateCastOrNull are unavailable?

    For instance, how can I test which strings in a given table can be safely casted to a specific array type?

  6. theory commented on Nov 12, 2025

    @theory
    Contributor

    EDIT: Ah, my comment dupes #38738


    FWIW, aggregate_functions_null_for_empty triggers this behavior, as well:

    hostname :) select groupArray(name) from system.codecs;
    
       ┌─groupArray(name)───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    1. │ ['GCD','AES_128_GCM_SIV','FPC','LZ4','AES_256_GCM_SIV','DoubleDelta','Gorilla','NONE','Multiple','LZ4HC','T64','Delta','ZSTD'] │
       └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
    
    hostname :) set aggregate_functions_null_for_empty = 1;
    
    Ok.
    
    hostname :) select groupArray(name) from system.codecs;
    
    Received exception from server (version 25.9.2):
    Code: 43. DB::Exception: Received from localhost:9000. DB::Exception: Nested type Array(String) cannot be inside Nullable type. (ILLEGAL_TYPE_OF_ARGUMENT)
    
  7. added
    comp-regular-function
    on Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-regular-functionunexpected behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions