@@ -316,75 +316,75 @@ select tableoid::regclass::text, a, min(b) as min_b, max(b) as max_b from list_p
316316-- cleanup
317317drop table range_parted, list_parted;
318318-- more tests for certain multi-level partitioning scenarios
319- create table p (a int, b int) partition by range (a, b);
320- create table p1 (b int not null, a int not null) partition by range ((b+0));
321- create table p11 (like p1 );
322- alter table p11 drop a;
323- alter table p11 add a int;
324- alter table p11 drop a;
325- alter table p11 add a int not null;
326- -- attnum for key attribute 'a' is different in p, p1 , and p11
319+ create table mlparted (a int, b int) partition by range (a, b);
320+ create table mlparted1 (b int not null, a int not null) partition by range ((b+0));
321+ create table mlparted11 (like mlparted1 );
322+ alter table mlparted11 drop a;
323+ alter table mlparted11 add a int;
324+ alter table mlparted11 drop a;
325+ alter table mlparted11 add a int not null;
326+ -- attnum for key attribute 'a' is different in mlparted, mlparted1 , and mlparted11
327327select attrelid::regclass, attname, attnum
328328from pg_attribute
329329where attname = 'a'
330- and (attrelid = 'p '::regclass
331- or attrelid = 'p1 '::regclass
332- or attrelid = 'p11 '::regclass)
330+ and (attrelid = 'mlparted '::regclass
331+ or attrelid = 'mlparted1 '::regclass
332+ or attrelid = 'mlparted11 '::regclass)
333333order by attrelid::regclass::text;
334- attrelid | attname | attnum
335- ----------+---------+--------
336- p | a | 1
337- p1 | a | 2
338- p11 | a | 4
334+ attrelid | attname | attnum
335+ ------------ +---------+--------
336+ mlparted | a | 1
337+ mlparted1 | a | 2
338+ mlparted11 | a | 4
339339(3 rows)
340340
341- alter table p1 attach partition p11 for values from (2) to (5);
342- alter table p attach partition p1 for values from (1, 2) to (1, 10);
343- -- check that "(1, 2)" is correctly routed to p11 .
344- insert into p values (1, 2);
345- select tableoid::regclass, * from p ;
346- tableoid | a | b
347- ----------+---+---
348- p11 | 1 | 2
341+ alter table mlparted1 attach partition mlparted11 for values from (2) to (5);
342+ alter table mlparted attach partition mlparted1 for values from (1, 2) to (1, 10);
343+ -- check that "(1, 2)" is correctly routed to mlparted11 .
344+ insert into mlparted values (1, 2);
345+ select tableoid::regclass, * from mlparted ;
346+ tableoid | a | b
347+ ------------ +---+---
348+ mlparted11 | 1 | 2
349349(1 row)
350350
351- -- check that proper message is shown after failure to route through p1
352- insert into p (a, b) values (1, 5);
353- ERROR: no partition of relation "p1 " found for row
351+ -- check that proper message is shown after failure to route through mlparted1
352+ insert into mlparted (a, b) values (1, 5);
353+ ERROR: no partition of relation "mlparted1 " found for row
354354DETAIL: Partition key of the failing row contains ((b + 0)) = (5).
355- truncate p ;
356- alter table p add constraint check_b check (b = 3);
357- -- check that correct input row is shown when constraint check_b fails on p11
355+ truncate mlparted ;
356+ alter table mlparted add constraint check_b check (b = 3);
357+ -- check that correct input row is shown when constraint check_b fails on mlparted11
358358-- after "(1, 2)" is routed to it
359- insert into p values (1, 2);
360- ERROR: new row for relation "p11 " violates check constraint "check_b"
359+ insert into mlparted values (1, 2);
360+ ERROR: new row for relation "mlparted11 " violates check constraint "check_b"
361361DETAIL: Failing row contains (1, 2).
362362-- check that inserting into an internal partition successfully results in
363363-- checking its partition constraint before inserting into the leaf partition
364364-- selected by tuple-routing
365- insert into p1 (a, b) values (2, 3);
366- ERROR: new row for relation "p11 " violates partition constraint
365+ insert into mlparted1 (a, b) values (2, 3);
366+ ERROR: new row for relation "mlparted11 " violates partition constraint
367367DETAIL: Failing row contains (3, 2).
368368-- check that RETURNING works correctly with tuple-routing
369- alter table p drop constraint check_b;
370- create table p12 partition of p1 for values from (5) to (10);
371- create table p2 (b int not null, a int not null);
372- alter table p attach partition p2 for values from (1, 10) to (1, 20);
373- create table p3 partition of p for values from (1, 20) to (1, 30);
374- create table p4 (like p );
375- alter table p4 drop a;
376- alter table p4 add a int not null;
377- alter table p attach partition p4 for values from (1, 30) to (1, 40);
369+ alter table mlparted drop constraint check_b;
370+ create table mlparted12 partition of mlparted1 for values from (5) to (10);
371+ create table mlparted2 (b int not null, a int not null);
372+ alter table mlparted attach partition mlparted2 for values from (1, 10) to (1, 20);
373+ create table mlparted3 partition of mlparted for values from (1, 20) to (1, 30);
374+ create table mlparted4 (like mlparted );
375+ alter table mlparted4 drop a;
376+ alter table mlparted4 add a int not null;
377+ alter table mlparted attach partition mlparted4 for values from (1, 30) to (1, 40);
378378with ins (a, b, c) as
379- (insert into p (b, a) select s.a, 1 from generate_series(2, 39) s(a) returning tableoid::regclass, *)
379+ (insert into mlparted (b, a) select s.a, 1 from generate_series(2, 39) s(a) returning tableoid::regclass, *)
380380 select a, b, min(c), max(c) from ins group by a, b order by 1;
381- a | b | min | max
382- -----+---+-----+-----
383- p11 | 1 | 2 | 4
384- p12 | 1 | 5 | 9
385- p2 | 1 | 10 | 19
386- p3 | 1 | 20 | 29
387- p4 | 1 | 30 | 39
381+ a | b | min | max
382+ ------------ +---+-----+-----
383+ mlparted11 | 1 | 2 | 4
384+ mlparted12 | 1 | 5 | 9
385+ mlparted2 | 1 | 10 | 19
386+ mlparted3 | 1 | 20 | 29
387+ mlparted4 | 1 | 30 | 39
388388(5 rows)
389389
390390-- check that message shown after failure to find a partition shows the
@@ -413,5 +413,3 @@ revoke all on key_desc from someone_else;
413413revoke all on key_desc_1 from someone_else;
414414drop role someone_else;
415415drop table key_desc, key_desc_1;
416- -- cleanup
417- drop table p;
0 commit comments