Fix incorrect column name in error message for range partition bound check

myzhen <zhenmingyang@yeah.net>

From: myzhen <zhenmingyang@yeah.net>
To: pgsql-hackers@lists.postgresql.org
Date: 2026-01-07T05:44:46Z
Lists: pgsql-hackers

Attachments

Hi all,
Recently, while working with partitioned tables, I identified an issue where the error message references an incorrect column name when a range-partitioned table’s boundary values include MINVALUE or MAXVALUE. 


For example:


postgres=# CREATE TABLE pt_test_colname(a int, b int, c int) PARTITION BY RANGE(a, b);
-- right case
postgres=# CREATE TABLE pt_test_colname_p1 PARTITION OF pt_test_colname FOR VALUES FROM (10, now()) TO (100, 100);
ERROR: specified value cannot be cast to type integer for column "b"
LINE 1: ...PARTITION OF pt_test_colname FOR VALUES FROM (10, now()) TO ...
                                                             ^
-- wrong case
postgres=# CREATE TABLE pt_test_colname_p1 PARTITION OF pt_test_colname FOR VALUES FROM (minvalue, now()) TO (100, 100);
ERROR: specified value cannot be cast to type integer for column "a"
LINE 1: ...ION OF pt_test_colname FOR VALUES FROM (minvalue, now()) TO ...
                                                             ^
The datetime value returned by now() cannot be cast to the partition key b (integer type), yet the error message incorrectly attributes this casting failure to column a when the preceding boundary value is the special MINVALUE or MAXVALUE.

Commits

  1. Fix possible incorrect column reference in ERROR message