]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix possible incorrect column reference in ERROR message
authorDavid Rowley <drowley@postgresql.org>
Thu, 8 Jan 2026 22:03:48 +0000 (11:03 +1300)
committerDavid Rowley <drowley@postgresql.org>
Thu, 8 Jan 2026 22:03:48 +0000 (11:03 +1300)
When creating a partition for a RANGE partitioned table, the reporting
of errors relating to converting the specified range values into
constant values for the partition key's type could display the name of a
previous partition key column when an earlier range was specified as
MINVALUE or MAXVALUE.

This was caused by the code not correctly incrementing the index that
tracks which partition key the foreach loop was working on after
processing MINVALUE/MAXVALUE ranges.

Fix by using foreach_current_index() to ensure the index variable is
always set to the List element being worked on.

Author: myzhen <zhenmingyang@yeah.net>
Reviewed-by: zhibin wang <killerwzb@gmail.com>
Discussion: https://postgr.es/m/273cab52.978.19b96fc75e7.Coremail.zhenmingyang@yeah.net
Backpatch-through: 14

src/backend/parser/parse_utilcmd.c

index 8fcaf15cd51d78a5e00c55a7ef847debf2cadaf5..c28fba347cc53fd1efcabb67f670f229a4b33d34 100644 (file)
@@ -4176,12 +4176,14 @@ transformPartitionRangeBounds(ParseState *pstate, List *blist,
        int                     i,
                                j;
 
-       i = j = 0;
+       j = 0;
        foreach(lc, blist)
        {
                Node       *expr = lfirst(lc);
                PartitionRangeDatum *prd = NULL;
 
+               i = foreach_current_index(lc);
+
                /*
                 * Infinite range bounds -- "minvalue" and "maxvalue" -- get passed in
                 * as ColumnRefs.
@@ -4259,7 +4261,6 @@ transformPartitionRangeBounds(ParseState *pstate, List *blist,
                        prd = makeNode(PartitionRangeDatum);
                        prd->kind = PARTITION_RANGE_DATUM_VALUE;
                        prd->value = (Node *) value;
-                       ++i;
                }
 
                prd->location = exprLocation(expr);