StarRocks/starrocks

DECIMAL(38,18) / DECIMAL(38,18) silently returns NULL due to overflow, while equivalent multiplication works correctly

Geschlossen

#73.784 geöffnet am 25.05.2026

 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Java (1.246 Forks)batch import
good first issuetype/bug

Repository-Metriken

Stars
 (5.717 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 5h) (1.000 gemergte PRs in 30 T)

Beschreibung

Issue

When dividing two DECIMAL(38,18) values (the maximum supported decimal precision in StarRocks), the result silently returns NULL due to precision overflow. The equivalent operation using multiplication with POW(..., -1) returns the correct result.

Steps to reproduce Returns NULL (bug)

SELECT CAST(2672.925686105492400095 AS DECIMAL(38,18))
     / CAST(421.193403692563637349 AS DECIMAL(38,18));

Returns 6.346076796721411 (works)

SELECT CAST(2672.925686105492400095 AS DECIMAL(38,18))
     * POW(CAST(421.193403692563637349 AS DECIMAL(38,18)), -1);

Workaround: explicit CAST to DOUBLE before division (works)

SELECT CAST(CAST(2672.925686105492400095 AS DECIMAL(38,18)) AS DOUBLE)
     / CAST(CAST(421.193403692563637349 AS DECIMAL(38,18)) AS DOUBLE);

Expected behavior

The session variable decimal_overflow_to_double should apply to the / operator the same way it applies to *.

Actual behavior

Division of two DECIMAL(38,18) values silently returns NULL. No error, no warning.

Starrocks version: 3.5.14

Contributor Guide