]> granicus.if.org Git - postgresql/commitdiff
Reverse-convert row types in ExecWithCheckOptions.
authorRobert Haas <rhaas@postgresql.org>
Tue, 18 Jul 2017 01:56:31 +0000 (21:56 -0400)
committerRobert Haas <rhaas@postgresql.org>
Tue, 18 Jul 2017 01:56:31 +0000 (21:56 -0400)
Just as we already do in ExecConstraints, and for the same reason:
to improve the quality of error messages.

Etsuro Fujita, reviewed by Amit Langote

Discussion: http://postgr.es/m/56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp

src/backend/executor/execMain.c
src/test/regress/expected/updatable_views.out

index df9302896c020735d0da8569b816c32477036e9c..b22de78516731e6de3a2f9d43ba61c2c3b1a4ccd 100644 (file)
@@ -2097,6 +2097,25 @@ ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
                                         * USING policy.
                                         */
                                case WCO_VIEW_CHECK:
+                                       /* See the comment in ExecConstraints(). */
+                                       if (resultRelInfo->ri_PartitionRoot)
+                                       {
+                                               HeapTuple       tuple = ExecFetchSlotTuple(slot);
+                                               TupleDesc       old_tupdesc = RelationGetDescr(rel);
+                                               TupleConversionMap *map;
+
+                                               rel = resultRelInfo->ri_PartitionRoot;
+                                               tupdesc = RelationGetDescr(rel);
+                                               /* a reverse map */
+                                               map = convert_tuples_by_name(old_tupdesc, tupdesc,
+                                                                                                        gettext_noop("could not convert row type"));
+                                               if (map != NULL)
+                                               {
+                                                       tuple = do_convert_tuple(tuple, map);
+                                                       ExecStoreTuple(tuple, slot, InvalidBuffer, false);
+                                               }
+                                       }
+
                                        insertedCols = GetInsertedColumns(resultRelInfo, estate);
                                        updatedCols = GetUpdatedColumns(resultRelInfo, estate);
                                        modifiedCols = bms_union(insertedCols, updatedCols);
index 971dddd01c5b03ae47786164a6113738391c6005..caca81a70b6b793d104e4715229fecc81fede116 100644 (file)
@@ -2424,6 +2424,6 @@ select tableoid::regclass, * from pt;
 create view ptv_wco as select * from pt where a = 0 with check option;
 insert into ptv_wco values (1, 2);
 ERROR:  new row violates check option for view "ptv_wco"
-DETAIL:  Failing row contains (2, 1).
+DETAIL:  Failing row contains (1, 2).
 drop view ptv, ptv_wco;
 drop table pt, pt1, pt11;