@@ -15168,15 +15168,11 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
15168
15168
*/
15169
15169
15170
15170
/*
15171
- * Cannot have expressions containing whole-row references or
15172
- * system column references.
15171
+ * Cannot allow system column references, since that would
15172
+ * make partition routing impossible: their values won't be
15173
+ * known yet when we need to do that.
15173
15174
*/
15174
15175
pull_varattnos(expr, 1, &expr_attrs);
15175
- if (bms_is_member(0 - FirstLowInvalidHeapAttributeNumber,
15176
- expr_attrs))
15177
- ereport(ERROR,
15178
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
15179
- errmsg("partition key expressions cannot contain whole-row references")));
15180
15176
for (i = FirstLowInvalidHeapAttributeNumber; i < 0; i++)
15181
15177
{
15182
15178
if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
@@ -15196,7 +15192,8 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
15196
15192
{
15197
15193
AttrNumber attno = i + FirstLowInvalidHeapAttributeNumber;
15198
15194
15199
- if (TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
15195
+ if (attno > 0 &&
15196
+ TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
15200
15197
ereport(ERROR,
15201
15198
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
15202
15199
errmsg("cannot use generated column in partition key"),
@@ -15451,7 +15448,6 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
15451
15448
for (i = 0; i < partdesc->nparts; i++)
15452
15449
{
15453
15450
Relation part_rel;
15454
- bool found_whole_row;
15455
15451
List *thisPartConstraint;
15456
15452
15457
15453
/*
@@ -15465,10 +15461,7 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
15465
15461
*/
15466
15462
thisPartConstraint =
15467
15463
map_partition_varattnos(partConstraint, 1,
15468
- part_rel, scanrel, &found_whole_row);
15469
- /* There can never be a whole-row reference here */
15470
- if (found_whole_row)
15471
- elog(ERROR, "unexpected whole-row reference found in partition constraint");
15464
+ part_rel, scanrel);
15472
15465
15473
15466
QueuePartitionConstraintValidation(wqueue, part_rel,
15474
15467
thisPartConstraint,
@@ -15497,7 +15490,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
15497
15490
TupleDesc tupleDesc;
15498
15491
ObjectAddress address;
15499
15492
const char *trigger_name;
15500
- bool found_whole_row;
15501
15493
Oid defaultPartOid;
15502
15494
List *partBoundConstraint;
15503
15495
@@ -15714,11 +15706,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
15714
15706
* numbers.
15715
15707
*/
15716
15708
partConstraint = map_partition_varattnos(partConstraint, 1, attachrel,
15717
- rel, &found_whole_row);
15718
- /* There can never be a whole-row reference here */
15719
- if (found_whole_row)
15720
- elog(ERROR,
15721
- "unexpected whole-row reference found in partition key");
15709
+ rel);
15722
15710
15723
15711
/* Validate partition constraints against the table being attached. */
15724
15712
QueuePartitionConstraintValidation(wqueue, attachrel, partConstraint,
@@ -15750,7 +15738,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
15750
15738
*/
15751
15739
defPartConstraint =
15752
15740
map_partition_varattnos(defPartConstraint,
15753
- 1, defaultrel, rel, NULL );
15741
+ 1, defaultrel, rel);
15754
15742
QueuePartitionConstraintValidation(wqueue, defaultrel,
15755
15743
defPartConstraint, true);
15756
15744
@@ -16004,19 +15992,11 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
16004
15992
RelationGetDescr(pg_trigger), &isnull);
16005
15993
if (!isnull)
16006
15994
{
16007
- bool found_whole_row;
16008
-
16009
15995
qual = stringToNode(TextDatumGetCString(value));
16010
15996
qual = (Node *) map_partition_varattnos((List *) qual, PRS2_OLD_VARNO,
16011
- partition, parent,
16012
- &found_whole_row);
16013
- if (found_whole_row)
16014
- elog(ERROR, "unexpected whole-row reference found in trigger WHEN clause");
15997
+ partition, parent);
16015
15998
qual = (Node *) map_partition_varattnos((List *) qual, PRS2_NEW_VARNO,
16016
- partition, parent,
16017
- &found_whole_row);
16018
- if (found_whole_row)
16019
- elog(ERROR, "unexpected whole-row reference found in trigger WHEN clause");
15999
+ partition, parent);
16020
16000
}
16021
16001
16022
16002
/*
0 commit comments