Skip to content

TRY_CAST returns an error instead of NULL for timestamp/date overflow #22896

Description

@fengys1996

Describe the bug

TRY_CAST should return NULL when a cast fails. However, timestamp/date casts that overflow during conversion currently return an error.

To Reproduce

  1. Timestamp(Second) -> Timestamp(Nanosecond) overflow:
SELECT TRY_CAST(
    arrow_cast(9223372037, 'Timestamp(s)')
    AS TIMESTAMP(9)
) AS ts;

actual output:

Optimizer rule 'simplify_expressions' failed
Execution("Cannot cast Timestamp(s) value 9223372037 to Timestamp(ns): converted value exceeds the representable i64 range")
  1. Date -> Timestamp(Nanosecond) overflow:
SELECT CAST(DATE '3000-01-01' AS TIMESTAMP(9)

actual output:

Optimizer rule 'simplify_expressions' failed
Execution("Cannot cast Date32 value 376200 to Timestamp(ns): converted value exceeds the representable i64 range")

Expected behavior

Both TRY_CAST queries should return NULL, while the equivalent CAST queries should continue to return errors.

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions