Skip to content

Comparisons return wrong results when timestamp and decimal TRY_CAST operations overflow #27689

Backlog

Description

@akoshchiy

Describe the bug

Comparisons against an overflowing TRY_CAST returned TRUE for two conversions: Timestamp(s) to TIMESTAMP(9) and BIGINT to DECIMAL(10,2). In both cases, using the comparison in a WHERE clause incorrectly kept the overflowing row.

To Reproduce

Run these statements in the DataFusion CLI:

-- Case 1: Timestamp(s) to TIMESTAMP(9). The year-2603 value overflows.
CREATE TABLE ts AS
SELECT arrow_cast(v, 'Timestamp(s)') AS t
FROM (VALUES (0), (20000000000)) AS x(v);

SELECT t,
TRY_CAST(t AS TIMESTAMP(9)) AS c,
TRY_CAST(t AS TIMESTAMP(9)) > TIMESTAMP '1970-01-01 00:00:01' AS try_gt
FROM ts
ORDER BY t;

SELECT t FROM ts
WHERE TRY_CAST(t AS TIMESTAMP(9)) > TIMESTAMP '1970-01-01 00:00:01';

-- Case 2: BIGINT to DECIMAL(10,2). The larger value exceeds the precision.
CREATE TABLE ints AS VALUES (5::bigint), (999999999999::bigint);

SELECT column1,
TRY_CAST(column1 AS DECIMAL(10,2)) AS c,
TRY_CAST(column1 AS DECIMAL(10,2)) > CAST(4 AS DECIMAL(10,2)) AS try_gt
FROM ints
ORDER BY column1;

SELECT column1 FROM ints
WHERE TRY_CAST(column1 AS DECIMAL(10,2)) > CAST(4 AS DECIMAL(10,2));

Expected behavior

For both overflowing inputs, c and try_gt should be NULL. A WHERE clause keeps only rows where the predicate is TRUE, so the timestamp filter should return no rows and the decimal filter should return only 5.

Additional context

A #24702 reports the same loss of NULL-on-overflow semantics for narrowing integer casts

Activity

  1. added
    bug
    on Nov 23, 2026
  2. added theissue type on Nov 23, 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

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions