@@ -15168,15 +15168,11 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
1516815168 */
1516915169
1517015170/*
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.
1517315174 */
1517415175pull_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")));
1518015176for (i = FirstLowInvalidHeapAttributeNumber; i < 0; i++)
1518115177{
1518215178if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
@@ -15196,7 +15192,8 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
1519615192{
1519715193AttrNumberattno = i + FirstLowInvalidHeapAttributeNumber;
1519815194
15199- if (TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
15195+ if (attno > 0 &&
15196+ TupleDescAttr(RelationGetDescr(rel), attno - 1)->attgenerated)
1520015197ereport(ERROR,
1520115198(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1520215199 errmsg("cannot use generated column in partition key"),
@@ -15451,7 +15448,6 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
1545115448for (i = 0; i < partdesc->nparts; i++)
1545215449{
1545315450Relationpart_rel;
15454- boolfound_whole_row;
1545515451List *thisPartConstraint;
1545615452
1545715453/*
@@ -15465,10 +15461,7 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
1546515461 */
1546615462thisPartConstraint =
1546715463map_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);
1547215465
1547315466QueuePartitionConstraintValidation(wqueue, part_rel,
1547415467 thisPartConstraint,
@@ -15497,7 +15490,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1549715490TupleDesctupleDesc;
1549815491ObjectAddress address;
1549915492const char *trigger_name;
15500- boolfound_whole_row;
1550115493OiddefaultPartOid;
1550215494List *partBoundConstraint;
1550315495
@@ -15714,11 +15706,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1571415706 * numbers.
1571515707 */
1571615708partConstraint = 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);
1572215710
1572315711/* Validate partition constraints against the table being attached. */
1572415712QueuePartitionConstraintValidation(wqueue, attachrel, partConstraint,
@@ -15750,7 +15738,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1575015738 */
1575115739defPartConstraint =
1575215740map_partition_varattnos(defPartConstraint,
15753- 1, defaultrel, rel, NULL );
15741+ 1, defaultrel, rel);
1575415742QueuePartitionConstraintValidation(wqueue, defaultrel,
1575515743 defPartConstraint, true);
1575615744
@@ -16004,19 +15992,11 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
1600415992 RelationGetDescr(pg_trigger), &isnull);
1600515993if (!isnull)
1600615994{
16007- boolfound_whole_row;
16008-
1600915995qual = stringToNode(TextDatumGetCString(value));
1601015996qual = (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);
1601515998qual = (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);
1602016000}
1602116001
1602216002/*