BUG #19722: Window PARTITION BY numeric treats equal values with different scales as separate partitions

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: 1482694023(at)qq(dot)com
Subject: BUG #19722: Window PARTITION BY numeric treats equal values with different scales as separate partitions
Date: 2026-09-26 08:55:20
Message-ID: 19722-1b775eae8675c158@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19722
Logged by: N J
Email address: 1482694023(at)qq(dot)com
PostgreSQL version: 18.6
Operating system: Windows 11 64-bit
Description:

Environment:
PostgreSQL: 18.6
OS: Windows 11 64-bit

Reproduction SQL:
CREATE TEMP TABLE decimal_source (raw_value text NOT NULL);
INSERT INTO decimal_source VALUES
('1.0'), ('1.00'), ('1.000');

SELECT amount, partition_size
FROM (
SELECT raw_value::numeric AS amount,
COUNT(*) OVER (PARTITION BY raw_value::numeric) AS partition_size
FROM decimal_source
) AS windowed
WHERE scale(amount) = 1;

Observed result:
amount | partition_size
--------+----------------
1.0 | 1

Expected result:
amount | partition_size
--------+----------------
1.0 | 3

Bug analysis:
All three text values convert to numerically equal numeric values (1.0,
1.00, 1.000 all represent the same number). According to standard SQL
semantics, PARTITION BY groups rows by value equality, so all three rows
should belong to the same window partition and COUNT(*) OVER should return 3
for every row.

The actual result shows partition_size = 1, which means values with
different decimal scales are incorrectly treated as distinct partition keys.
The window partition logic appears to use the internal representation
(including scale metadata) instead of logical numeric equality to determine
partition membership.

This is a correctness bug: numerically equal values must be grouped into the
same window partition regardless of their precision/scale.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-09-26 09:00:00 BUG #19723: CREATE INDEX racing with ALTER INDEX ATTACH PARTITION triggers unexpected internal error
Previous Message Andrey Rachitskiy 2026-09-26 08:55:02 Re: BUG #19721: json_value with DEFAULT ON ERROR returns inconsistent results for NULL input in materialized CTE