#122613·ClickHouse

ILLEGAL_COLUMN for a valid INNER JOIN with two Decimal CAST predicates; equivalent INTERSECT DISTINCT query succeeds

Author: Manuel-Neuer1Created Sep 28, 2026Updated Sep 29, 2026
Labelscomp-joinspotential bugexternal

Company or project name

No response

Describe what's wrong

On ClickHouse 26.8.2.7 (official build), a one-row INNER ALL JOIN whose ON clause contains two true Decimal comparisons fails with server error Code 44 (ILLEGAL_COLUMN). Each comparison succeeds on its own. A direct INTERSECT DISTINCT rewrite, without derived tables, returns the expected row identity 0. The reported issue is the server error on the conjunctive query. This is not a confirmed wrong-result comparison: the failing query produces no complete result. No server crash was observed. ClickHouse Fiddle reproducer: NOT_TESTED.

Does it reproduce on the most recent release?

Yes

How to reproduce

sql

DROP DATABASE IF EXISTS test;
CREATE DATABASE IF NOT EXISTS test;
USE test;

CREATE TABLE test.t1 (id UInt32, k UInt32) ENGINE = Log;
CREATE TABLE test.t3 (id UInt32, k UInt32) ENGINE = MergeTree ORDER BY k;
INSERT INTO test.t1 VALUES (0, 0);
INSERT INTO test.t3 VALUES (0, 0);


-- base query: code:44
SELECT t1.id AS psd_id
FROM t1 INNER ALL JOIN t3
ON t1.k = t3.k
   AND CAST(t1.k AS Decimal(38, 6)) = CAST(t3.k AS Decimal(38, 6))
   AND CAST(t3.k AS Decimal(38, 6)) >= CAST(t1.k AS Decimal(38, 6));

-- rewirte query: {0}
SELECT t1.id AS psd_id
FROM t1 INNER ALL JOIN t3
ON t1.k = t3.k
   AND CAST(t1.k AS Decimal(38, 6)) = CAST(t3.k AS Decimal(38, 6))
INTERSECT DISTINCT
SELECT t1.id AS psd_id
FROM t1 INNER ALL JOIN t3
ON t1.k = t3.k
   AND CAST(t3.k AS Decimal(38, 6)) >= CAST(t1.k AS Decimal(38, 6));

As you can see in https://fiddle.clickhouse.com/01ba1cb3-5b58-4d67-8341-ef6c0167b6ff

Expected behavior

The conjunctive query should complete and return one row '0'.

Error message and/or stacktrace

sql
Received exception from server (version 26.9.4):
Code: 44. DB::Exception: Received from localhost:9000. DB::Exception: Illegal column Decimal128 of first argument of function CAST: while executing 'FUNCTION CAST(CAST(__table2.k, 'Decimal(38, 6)'_String) : 3, 'Decimal(38, 6)'_String :: 1) -> CAST(CAST(__table2.k, 'Decimal(38, 6)'_String), 'Decimal(38, 6)'_String) Decimal(38, 6) : 0'. (ILLEGAL_COLUMN)
(query: -- base query: code:44
SELECT t1.id AS psd_id
FROM t1 INNER ALL JOIN t3
ON t1.k = t3.k
   AND CAST(t1.k AS Decimal(38, 6)) = CAST(t3.k AS Decimal(38, 6))
   AND CAST(t3.k AS Decimal(38, 6)) >= CAST(t1.k AS Decimal(38, 6));)

Related issues and pull requests

No response

Additional context

No response