From cb919ba074f7cf20019aeef17f381d7f0cfe4a6a Mon Sep 17 00:00:00 2001 From: amit Date: Mon, 10 Jul 2017 15:26:58 +0900 Subject: [PATCH 2/2] Correctly format the row shown in WITH CHECK OPTION error message Author: Etsuro Fujita --- src/backend/executor/execMain.c | 19 +++++++++++++++++++ src/test/regress/expected/updatable_views.out | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index c36b5b7392..d7bfb939b1 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -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); diff --git a/src/test/regress/expected/updatable_views.out b/src/test/regress/expected/updatable_views.out index 971dddd01c..caca81a70b 100644 --- a/src/test/regress/expected/updatable_views.out +++ b/src/test/regress/expected/updatable_views.out @@ -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; -- 2.11.0