@@ -1837,25 +1837,26 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
1837
1837
TupleTableSlot * slot ,
1838
1838
EState * estate )
1839
1839
{
1840
- Relation rel = resultRelInfo -> ri_RelationDesc ;
1841
- Relation orig_rel = rel ;
1842
- TupleDesc tupdesc = RelationGetDescr (rel );
1840
+ Oid root_relid ;
1841
+ TupleDesc tupdesc ;
1843
1842
char * val_desc ;
1844
1843
Bitmapset * modifiedCols ;
1845
- Bitmapset * insertedCols ;
1846
- Bitmapset * updatedCols ;
1847
1844
1848
1845
/*
1849
- * Need to first convert the tuple to the root partitioned table's row
1850
- * type. For details, check similar comments in ExecConstraints().
1846
+ * If the tuple has been routed, it's been converted to the partition's
1847
+ * rowtype, which might differ from the root table's. We must convert it
1848
+ * back to the root table's rowtype so that val_desc in the error message
1849
+ * matches the input tuple.
1851
1850
*/
1852
1851
if (resultRelInfo -> ri_PartitionRoot )
1853
1852
{
1854
- TupleDesc old_tupdesc = RelationGetDescr ( rel ) ;
1853
+ TupleDesc old_tupdesc ;
1855
1854
AttrNumber * map ;
1856
1855
1857
- rel = resultRelInfo -> ri_PartitionRoot ;
1858
- tupdesc = RelationGetDescr (rel );
1856
+ root_relid = RelationGetRelid (resultRelInfo -> ri_PartitionRoot );
1857
+ tupdesc = RelationGetDescr (resultRelInfo -> ri_PartitionRoot );
1858
+
1859
+ old_tupdesc = RelationGetDescr (resultRelInfo -> ri_RelationDesc );
1859
1860
/* a reverse map */
1860
1861
map = convert_tuples_by_name_map_if_req (old_tupdesc , tupdesc ,
1861
1862
gettext_noop ("could not convert row type" ));
@@ -1868,19 +1869,24 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
1868
1869
slot = execute_attr_map_slot (map , slot ,
1869
1870
MakeTupleTableSlot (tupdesc , & TTSOpsVirtual ));
1870
1871
}
1872
+ else
1873
+ {
1874
+ root_relid = RelationGetRelid (resultRelInfo -> ri_RelationDesc );
1875
+ tupdesc = RelationGetDescr (resultRelInfo -> ri_RelationDesc );
1876
+ }
1877
+
1878
+ modifiedCols = bms_add_members (GetInsertedColumns (resultRelInfo , estate ),
1879
+ GetUpdatedColumns (resultRelInfo , estate ));
1871
1880
1872
- insertedCols = GetInsertedColumns (resultRelInfo , estate );
1873
- updatedCols = GetUpdatedColumns (resultRelInfo , estate );
1874
- modifiedCols = bms_union (insertedCols , updatedCols );
1875
- val_desc = ExecBuildSlotValueDescription (RelationGetRelid (rel ),
1881
+ val_desc = ExecBuildSlotValueDescription (root_relid ,
1876
1882
slot ,
1877
1883
tupdesc ,
1878
1884
modifiedCols ,
1879
1885
64 );
1880
1886
ereport (ERROR ,
1881
1887
(errcode (ERRCODE_CHECK_VIOLATION ),
1882
1888
errmsg ("new row for relation \"%s\" violates partition constraint" ,
1883
- RelationGetRelationName (orig_rel )),
1889
+ RelationGetRelationName (resultRelInfo -> ri_RelationDesc )),
1884
1890
val_desc ? errdetail ("Failing row contains %s." , val_desc ) : 0 ));
1885
1891
}
1886
1892
0 commit comments