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

Started by 甄明洋11 months ago5 messageshackers
Jump to latest
#1甄明洋
zhenmingyang@yeah.net

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.

Attachments:

v1-0001-Fix-incorrect-column-name-in-error-message-for-range.patchapplication/octet-stream; name=v1-0001-Fix-incorrect-column-name-in-error-message-for-range.patch; x-cm-securityLevel=0Download+1-2
#2zhibin wang
killerwzb@gmail.com
In reply to: 甄明洋 (#1)
Re: Fix incorrect column name in error message for range partition bound check

Hi myzhen,

On Wed, Jan 7, 2026 at 1:48 PM myzhen <zhenmingyang@yeah.net> wrote:

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.

Yes, I think you are correct. It seems that this is an error prompt caused
by the infinite boundary values MINVALUE and MAXVALUE.

By the way, based on the context, once a column is set to MINVALUE or
MAXVALUE, the values of the remaining columns must be the same. However, I
noticed that 'validateInfiniteBounds' is only invoked after all boundary
value transformations are completed. Perhaps we can perform the validity
check for infinite boundary values earlier. In this way, we can not only
avoid this error but also achieve timely "short-circuit" — because any
non-MINVALUE transformation performed after MINVALUE is essentially
meaningless overhead. ideas?

#3甄明洋
zhenmingyang@yeah.net
In reply to: zhibin wang (#2)
Re:Re: Fix incorrect column name in error message for range partition bound check

Hi zhibin,

By the way, based on the context, once a column is set to MINVALUE or MAXVALUE, the values of the remaining columns must be the same. However, I noticed that 'validateInfiniteBounds' is only invoked after all boundary value transformations are completed. Perhaps we can perform the validity check for infinite boundary values earlier. In this way, we can not only avoid this error but also achieve timely "short-circuit" — because any non-MINVALUE transformation performed after MINVALUE is essentially meaningless overhead. ideas?

Thanks, I think it makes some sense, so I tried to make the second version.

Attachments:

v2-Fix-incorrect-column-name-in-error-message-for-range.patchapplication/octet-stream; name=v2-Fix-incorrect-column-name-in-error-message-for-range.patch; x-cm-securityLevel=0Download+35-51
#4甄明洋
zhenmingyang@yeah.net
In reply to: 甄明洋 (#1)
Re:Re: Re: Fix incorrect column name in error message for range partition bound check

Um, yes, as long as this problem can be solved, that's fine.
patch v2 may do less and reduce unnecessary transforms,
but the impact on DDL is minimal and may not need to be considered.

At 2026-01-08 08:36:06, "Eden Wang" <wanglintao_cn@163.com> wrote:

Hi myzhen,

Hmmm...personally, I prefer the first patch – it resolves this issue and is more concise.

Eden Wang

#5David Rowley
dgrowleyml@gmail.com
In reply to: 甄明洋 (#1)
Re: Fix incorrect column name in error message for range partition bound check

On Wed, 7 Jan 2026 at 18:45, myzhen <zhenmingyang@yeah.net> wrote:

postgres=# CREATE TABLE pt_test_colname(a int, b int, c int) PARTITION BY RANGE(a, b);

-- 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 ...

(I thought I'd sent this email last week, but I don't see it in the
archives or my sent items)

I've pushed a fix similar to your v1 patch for this. I used
foreach_current_index rather than what you did in your v1. That seems
less prone to get broken again in the future if someone were to add
additional logic within the loop body.

I didn't see any need to do any more than that, so I didn't consider
anything your v2 patch did.

Thanks for the patch.

David