Before, we always used a dummy value of 1, but that's not right when
the partitioned table being modified is inside of a WITH clause
rather than part of the main query.
Amit Langote, reported and reviewd by Etsuro Fujita, with a comment
change by me.
Discussion: http://postgr.es/m/
ee12f648-8907-77b5-afc0-
2980bcb0aa37@lab.ntt.co.jp
index fc5f4f66ead1ff92bec1d01f6a66a4c28875dd46..53e296559a951ca2f28220f1872bca4bb33a8052 100644 (file)
num_partitions;
ExecSetupPartitionTupleRouting(rel,
+ 1,
&partition_dispatch_info,
&partitions,
&partition_tupconv_maps,
index 0f08283f81f151dd99f4cc2c2c06d10bc581d560..df9302896c020735d0da8569b816c32477036e9c 100644 (file)
*/
void
ExecSetupPartitionTupleRouting(Relation rel,
+ Index resultRTindex,
PartitionDispatch **pd,
ResultRelInfo **partitions,
TupleConversionMap ***tup_conv_maps,
InitResultRelInfo(leaf_part_rri,
partrel,
- 1, /* dummy */
+ resultRTindex,
rel,
0);
index 8d17425abea2c3aeef6b919c16a3fb445e67e99b..77ba15dd9005c620eac160651de3d3f5c134b79c 100644 (file)
@@ -1914,6 +1914,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
num_partitions;
ExecSetupPartitionTupleRouting(rel,
+ node->nominalRelation,
&partition_dispatch_info,
&partitions,
&partition_tupconv_maps,
index e25cfa3ababc752c1ea04ca33ec132d7ec2bf68c..59c28b709e665cb95cfa7658e286ca1a2bbc8c90 100644 (file)
@@ -207,6 +207,7 @@ extern void EvalPlanQualSetTuple(EPQState *epqstate, Index rti,
HeapTuple tuple);
extern HeapTuple EvalPlanQualGetTuple(EPQState *epqstate, Index rti);
extern void ExecSetupPartitionTupleRouting(Relation rel,
+ Index resultRTindex,
PartitionDispatch **pd,
ResultRelInfo **partitions,
TupleConversionMap ***tup_conv_maps,
index d1153f410baf6fce15da0aa642c9211f9f131765..dd5dddb20cb70094b9964644ecb6d79b23ad5790 100644 (file)
insert into brtrigpartcon1 values (1, 'hi there');
ERROR: new row for relation "brtrigpartcon1" violates partition constraint
DETAIL: Failing row contains (2, hi there).
+-- check that the message shows the appropriate column description in a
+-- situation where the partitioned table is not the primary ModifyTable node
+create table inserttest3 (f1 text default 'foo', f2 text default 'bar', f3 int);
+create role regress_coldesc_role;
+grant insert on inserttest3 to regress_coldesc_role;
+grant insert on brtrigpartcon to regress_coldesc_role;
+revoke select on brtrigpartcon from regress_coldesc_role;
+set role regress_coldesc_role;
+with result as (insert into brtrigpartcon values (1, 'hi there') returning 1)
+ insert into inserttest3 (f3) select * from result;
+ERROR: new row for relation "brtrigpartcon1" violates partition constraint
+DETAIL: Failing row contains (a, b) = (2, hi there).
+reset role;
+-- cleanup
+revoke all on inserttest3 from regress_coldesc_role;
+revoke all on brtrigpartcon from regress_coldesc_role;
+drop role regress_coldesc_role;
+drop table inserttest3;
drop table brtrigpartcon;
drop function brtrigpartcon1trigf();
index 83c3ad8f534954185e1950c471b10f9fc7a5d882..fe63020768a90fd7f32cb80ccf5c2649e4f63723 100644 (file)
@@ -340,5 +340,23 @@ create or replace function brtrigpartcon1trigf() returns trigger as $$begin new.
create trigger brtrigpartcon1trig before insert on brtrigpartcon1 for each row execute procedure brtrigpartcon1trigf();
insert into brtrigpartcon values (1, 'hi there');
insert into brtrigpartcon1 values (1, 'hi there');
+
+-- check that the message shows the appropriate column description in a
+-- situation where the partitioned table is not the primary ModifyTable node
+create table inserttest3 (f1 text default 'foo', f2 text default 'bar', f3 int);
+create role regress_coldesc_role;
+grant insert on inserttest3 to regress_coldesc_role;
+grant insert on brtrigpartcon to regress_coldesc_role;
+revoke select on brtrigpartcon from regress_coldesc_role;
+set role regress_coldesc_role;
+with result as (insert into brtrigpartcon values (1, 'hi there') returning 1)
+ insert into inserttest3 (f3) select * from result;
+reset role;
+
+-- cleanup
+revoke all on inserttest3 from regress_coldesc_role;
+revoke all on brtrigpartcon from regress_coldesc_role;
+drop role regress_coldesc_role;
+drop table inserttest3;
drop table brtrigpartcon;
drop function brtrigpartcon1trigf();