2 -- insert with DEFAULT in the target_list
4 create table inserttest (col1 int4, col2 int4 NOT NULL, col3 text default 'testing');
5 insert into inserttest (col1, col2, col3) values (DEFAULT, DEFAULT, DEFAULT);
6 ERROR: null value in column "col2" violates not-null constraint
7 DETAIL: Failing row contains (null, null, testing).
8 insert into inserttest (col2, col3) values (3, DEFAULT);
9 insert into inserttest (col1, col2, col3) values (DEFAULT, 5, DEFAULT);
10 insert into inserttest values (DEFAULT, 5, 'test');
11 insert into inserttest values (DEFAULT, 7);
12 select * from inserttest;
14 ------+------+---------
22 -- insert with similar expression / target_list values (all fail)
24 insert into inserttest (col1, col2, col3) values (DEFAULT, DEFAULT);
25 ERROR: INSERT has more target columns than expressions
26 LINE 1: insert into inserttest (col1, col2, col3) values (DEFAULT, D...
28 insert into inserttest (col1, col2, col3) values (1, 2);
29 ERROR: INSERT has more target columns than expressions
30 LINE 1: insert into inserttest (col1, col2, col3) values (1, 2);
32 insert into inserttest (col1) values (1, 2);
33 ERROR: INSERT has more expressions than target columns
34 LINE 1: insert into inserttest (col1) values (1, 2);
36 insert into inserttest (col1) values (DEFAULT, DEFAULT);
37 ERROR: INSERT has more expressions than target columns
38 LINE 1: insert into inserttest (col1) values (DEFAULT, DEFAULT);
40 select * from inserttest;
42 ------+------+---------
52 insert into inserttest values(10, 20, '40'), (-1, 2, DEFAULT),
53 ((select 2), (select i from (values(3)) as foo (i)), 'values are fun!');
54 select * from inserttest;
56 ------+------+-----------------
63 2 | 3 | values are fun!
69 insert into inserttest values(30, 50, repeat('x', 10000));
70 select col1, col2, char_length(col3) from inserttest;
71 col1 | col2 | char_length
72 ------+------+-------------
83 drop table inserttest;
85 -- check indirection (field/array assignment), cf bug #14265
87 -- these tests are aware that transformInsertStmt has 3 separate code paths
89 create type insert_test_type as (if1 int, if2 text[]);
90 create table inserttest (f1 int, f2 int[],
91 f3 insert_test_type, f4 insert_test_type[]);
92 insert into inserttest (f2[1], f2[2]) values (1,2);
93 insert into inserttest (f2[1], f2[2]) values (3,4), (5,6);
94 insert into inserttest (f2[1], f2[2]) select 7,8;
95 insert into inserttest (f2[1], f2[2]) values (1,default); -- not supported
96 ERROR: cannot set an array element to DEFAULT
97 LINE 1: insert into inserttest (f2[1], f2[2]) values (1,default);
99 insert into inserttest (f3.if1, f3.if2) values (1,array['foo']);
100 insert into inserttest (f3.if1, f3.if2) values (1,'{foo}'), (2,'{bar}');
101 insert into inserttest (f3.if1, f3.if2) select 3, '{baz,quux}';
102 insert into inserttest (f3.if1, f3.if2) values (1,default); -- not supported
103 ERROR: cannot set a subfield to DEFAULT
104 LINE 1: insert into inserttest (f3.if1, f3.if2) values (1,default);
106 insert into inserttest (f3.if2[1], f3.if2[2]) values ('foo', 'bar');
107 insert into inserttest (f3.if2[1], f3.if2[2]) values ('foo', 'bar'), ('baz', 'quux');
108 insert into inserttest (f3.if2[1], f3.if2[2]) select 'bear', 'beer';
109 insert into inserttest (f4[1].if2[1], f4[1].if2[2]) values ('foo', 'bar');
110 insert into inserttest (f4[1].if2[1], f4[1].if2[2]) values ('foo', 'bar'), ('baz', 'quux');
111 insert into inserttest (f4[1].if2[1], f4[1].if2[2]) select 'bear', 'beer';
112 select * from inserttest;
114 ----+-------+------------------+------------------------
122 | | (3,"{baz,quux}") |
125 | | (,"{baz,quux}") |
126 | | (,"{bear,beer}") |
127 | | | {"(,\"{foo,bar}\")"}
128 | | | {"(,\"{foo,bar}\")"}
129 | | | {"(,\"{baz,quux}\")"}
130 | | | {"(,\"{bear,beer}\")"}
133 -- also check reverse-listing
134 create table inserttest2 (f1 bigint, f2 text);
135 create rule irule1 as on insert to inserttest2 do also
136 insert into inserttest (f3.if2[1], f3.if2[2])
137 values (new.f1,new.f2);
138 create rule irule2 as on insert to inserttest2 do also
139 insert into inserttest (f4[1].if1, f4[1].if2[2])
140 values (1,'fool'),(new.f1,new.f2);
141 create rule irule3 as on insert to inserttest2 do also
142 insert into inserttest (f4[1].if1, f4[1].if2[2])
143 select new.f1, new.f2;
145 Table "public.inserttest2"
146 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
147 --------+--------+-----------+----------+---------+----------+--------------+-------------
148 f1 | bigint | | | | plain | |
149 f2 | text | | | | extended | |
152 ON INSERT TO inserttest2 DO INSERT INTO inserttest (f3.if2[1], f3.if2[2])
153 VALUES (new.f1, new.f2)
155 ON INSERT TO inserttest2 DO INSERT INTO inserttest (f4[1].if1, f4[1].if2[2]) VALUES (1,'fool'::text), (new.f1,new.f2)
157 ON INSERT TO inserttest2 DO INSERT INTO inserttest (f4[1].if1, f4[1].if2[2]) SELECT new.f1,
160 drop table inserttest2;
161 drop table inserttest;
162 drop type insert_test_type;
163 -- direct partition inserts should check partition bound constraint
164 create table range_parted (
167 ) partition by range (a, (b+0));
168 create table part1 partition of range_parted for values from ('a', 1) to ('a', 10);
169 create table part2 partition of range_parted for values from ('a', 10) to ('a', 20);
170 create table part3 partition of range_parted for values from ('b', 1) to ('b', 10);
171 create table part4 partition of range_parted for values from ('b', 10) to ('b', 20);
173 insert into part1 values ('a', 11);
174 ERROR: new row for relation "part1" violates partition constraint
175 DETAIL: Failing row contains (a, 11).
176 insert into part1 values ('b', 1);
177 ERROR: new row for relation "part1" violates partition constraint
178 DETAIL: Failing row contains (b, 1).
180 insert into part1 values ('a', 1);
182 insert into part4 values ('b', 21);
183 ERROR: new row for relation "part4" violates partition constraint
184 DETAIL: Failing row contains (b, 21).
185 insert into part4 values ('a', 10);
186 ERROR: new row for relation "part4" violates partition constraint
187 DETAIL: Failing row contains (a, 10).
189 insert into part4 values ('b', 10);
190 -- fail (partition key a has a NOT NULL constraint)
191 insert into part1 values (null);
192 ERROR: new row for relation "part1" violates partition constraint
193 DETAIL: Failing row contains (null, null).
194 -- fail (expression key (b+0) cannot be null either)
195 insert into part1 values (1);
196 ERROR: new row for relation "part1" violates partition constraint
197 DETAIL: Failing row contains (1, null).
198 create table list_parted (
201 ) partition by list (lower(a));
202 create table part_aa_bb partition of list_parted FOR VALUES IN ('aa', 'bb');
203 create table part_cc_dd partition of list_parted FOR VALUES IN ('cc', 'dd');
204 create table part_null partition of list_parted FOR VALUES IN (null);
206 insert into part_aa_bb values ('cc', 1);
207 ERROR: new row for relation "part_aa_bb" violates partition constraint
208 DETAIL: Failing row contains (cc, 1).
209 insert into part_aa_bb values ('AAa', 1);
210 ERROR: new row for relation "part_aa_bb" violates partition constraint
211 DETAIL: Failing row contains (AAa, 1).
212 insert into part_aa_bb values (null);
213 ERROR: new row for relation "part_aa_bb" violates partition constraint
214 DETAIL: Failing row contains (null, null).
216 insert into part_cc_dd values ('cC', 1);
217 insert into part_null values (null, 0);
218 -- check in case of multi-level partitioned table
219 create table part_ee_ff partition of list_parted for values in ('ee', 'ff') partition by range (b);
220 create table part_ee_ff1 partition of part_ee_ff for values from (1) to (10);
221 create table part_ee_ff2 partition of part_ee_ff for values from (10) to (20);
223 insert into part_ee_ff1 values ('EE', 11);
224 ERROR: new row for relation "part_ee_ff1" violates partition constraint
225 DETAIL: Failing row contains (EE, 11).
226 -- fail (even the parent's, ie, part_ee_ff's partition constraint applies)
227 insert into part_ee_ff1 values ('cc', 1);
228 ERROR: new row for relation "part_ee_ff1" violates partition constraint
229 DETAIL: Failing row contains (cc, 1).
231 insert into part_ee_ff1 values ('ff', 1);
232 insert into part_ee_ff2 values ('ff', 11);
233 -- Check tuple routing for partitioned tables
235 insert into range_parted values ('a', 0);
236 ERROR: no partition of relation "range_parted" found for row
237 DETAIL: Partition key of the failing row contains (a, (b + 0)) = (a, 0).
239 insert into range_parted values ('a', 1);
240 insert into range_parted values ('a', 10);
242 insert into range_parted values ('a', 20);
243 ERROR: no partition of relation "range_parted" found for row
244 DETAIL: Partition key of the failing row contains (a, (b + 0)) = (a, 20).
246 insert into range_parted values ('b', 1);
247 insert into range_parted values ('b', 10);
248 -- fail (partition key (b+0) is null)
249 insert into range_parted values ('a');
250 ERROR: no partition of relation "range_parted" found for row
251 DETAIL: Partition key of the failing row contains (a, (b + 0)) = (a, null).
252 select tableoid::regclass, * from range_parted;
264 insert into list_parted values (null, 1);
265 insert into list_parted (a) values ('aA');
266 -- fail (partition of part_ee_ff not found in both cases)
267 insert into list_parted values ('EE', 0);
268 ERROR: no partition of relation "part_ee_ff" found for row
269 DETAIL: Partition key of the failing row contains (b) = (0).
270 insert into part_ee_ff values ('EE', 0);
271 ERROR: no partition of relation "part_ee_ff" found for row
272 DETAIL: Partition key of the failing row contains (b) = (0).
274 insert into list_parted values ('EE', 1);
275 insert into part_ee_ff values ('EE', 10);
276 select tableoid::regclass, * from list_parted;
278 -------------+----+----
285 part_ee_ff2 | ff | 11
286 part_ee_ff2 | EE | 10
289 -- some more tests to exercise tuple-routing with multi-level partitioning
290 create table part_gg partition of list_parted for values in ('gg') partition by range (b);
291 create table part_gg1 partition of part_gg for values from (minvalue) to (1);
292 create table part_gg2 partition of part_gg for values from (1) to (10) partition by range (b);
293 create table part_gg2_1 partition of part_gg2 for values from (1) to (5);
294 create table part_gg2_2 partition of part_gg2 for values from (5) to (10);
295 create table part_ee_ff3 partition of part_ee_ff for values from (20) to (30) partition by range (b);
296 create table part_ee_ff3_1 partition of part_ee_ff3 for values from (20) to (25);
297 create table part_ee_ff3_2 partition of part_ee_ff3 for values from (25) to (30);
298 truncate list_parted;
299 insert into list_parted values ('aa'), ('cc');
300 insert into list_parted select 'Ff', s.a from generate_series(1, 29) s(a);
301 insert into list_parted select 'gg', s.a from generate_series(1, 9) s(a);
302 insert into list_parted (b) values (1);
303 select tableoid::regclass::text, a, min(b) as min_b, max(b) as max_b from list_parted group by 1, 2 order by 1;
304 tableoid | a | min_b | max_b
305 ---------------+----+-------+-------
308 part_ee_ff1 | Ff | 1 | 9
309 part_ee_ff2 | Ff | 10 | 19
310 part_ee_ff3_1 | Ff | 20 | 24
311 part_ee_ff3_2 | Ff | 25 | 29
312 part_gg2_1 | gg | 1 | 4
313 part_gg2_2 | gg | 5 | 9
318 drop table range_parted, list_parted;
319 -- more tests for certain multi-level partitioning scenarios
320 create table mlparted (a int, b int) partition by range (a, b);
321 create table mlparted1 (b int not null, a int not null) partition by range ((b+0));
322 create table mlparted11 (like mlparted1);
323 alter table mlparted11 drop a;
324 alter table mlparted11 add a int;
325 alter table mlparted11 drop a;
326 alter table mlparted11 add a int not null;
327 -- attnum for key attribute 'a' is different in mlparted, mlparted1, and mlparted11
328 select attrelid::regclass, attname, attnum
331 and (attrelid = 'mlparted'::regclass
332 or attrelid = 'mlparted1'::regclass
333 or attrelid = 'mlparted11'::regclass)
334 order by attrelid::regclass::text;
335 attrelid | attname | attnum
336 ------------+---------+--------
342 alter table mlparted1 attach partition mlparted11 for values from (2) to (5);
343 alter table mlparted attach partition mlparted1 for values from (1, 2) to (1, 10);
344 -- check that "(1, 2)" is correctly routed to mlparted11.
345 insert into mlparted values (1, 2);
346 select tableoid::regclass, * from mlparted;
352 -- check that proper message is shown after failure to route through mlparted1
353 insert into mlparted (a, b) values (1, 5);
354 ERROR: no partition of relation "mlparted1" found for row
355 DETAIL: Partition key of the failing row contains ((b + 0)) = (5).
357 alter table mlparted add constraint check_b check (b = 3);
358 -- have a BR trigger modify the row such that the check_b is violated
359 create function mlparted11_trig_fn()
368 create trigger mlparted11_trig before insert ON mlparted11
369 for each row execute procedure mlparted11_trig_fn();
370 -- check that the correct row is shown when constraint check_b fails after
371 -- "(1, 2)" is routed to mlparted11 (actually "(1, 4)" would be shown due
372 -- to the BR trigger mlparted11_trig_fn)
373 insert into mlparted values (1, 2);
374 ERROR: new row for relation "mlparted11" violates check constraint "check_b"
375 DETAIL: Failing row contains (1, 4).
376 drop trigger mlparted11_trig on mlparted11;
377 drop function mlparted11_trig_fn();
378 -- check that inserting into an internal partition successfully results in
379 -- checking its partition constraint before inserting into the leaf partition
380 -- selected by tuple-routing
381 insert into mlparted1 (a, b) values (2, 3);
382 ERROR: new row for relation "mlparted1" violates partition constraint
383 DETAIL: Failing row contains (3, 2).
384 -- check routing error through a list partitioned table when the key is null
385 create table lparted_nonullpart (a int, b char) partition by list (b);
386 create table lparted_nonullpart_a partition of lparted_nonullpart for values in ('a');
387 insert into lparted_nonullpart values (1);
388 ERROR: no partition of relation "lparted_nonullpart" found for row
389 DETAIL: Partition key of the failing row contains (b) = (null).
390 drop table lparted_nonullpart;
391 -- check that RETURNING works correctly with tuple-routing
392 alter table mlparted drop constraint check_b;
393 create table mlparted12 partition of mlparted1 for values from (5) to (10);
394 create table mlparted2 (b int not null, a int not null);
395 alter table mlparted attach partition mlparted2 for values from (1, 10) to (1, 20);
396 create table mlparted3 partition of mlparted for values from (1, 20) to (1, 30);
397 create table mlparted4 (like mlparted);
398 alter table mlparted4 drop a;
399 alter table mlparted4 add a int not null;
400 alter table mlparted attach partition mlparted4 for values from (1, 30) to (1, 40);
401 with ins (a, b, c) as
402 (insert into mlparted (b, a) select s.a, 1 from generate_series(2, 39) s(a) returning tableoid::regclass, *)
403 select a, b, min(c), max(c) from ins group by a, b order by 1;
405 ------------+---+-----+-----
406 mlparted11 | 1 | 2 | 4
407 mlparted12 | 1 | 5 | 9
408 mlparted2 | 1 | 10 | 19
409 mlparted3 | 1 | 20 | 29
410 mlparted4 | 1 | 30 | 39
413 alter table mlparted add c text;
414 create table mlparted5 (c text, a int not null, b int not null) partition by list (c);
415 create table mlparted5a (a int not null, c text, b int not null);
416 alter table mlparted5 attach partition mlparted5a for values in ('a');
417 alter table mlparted attach partition mlparted5 for values from (1, 40) to (1, 50);
418 alter table mlparted add constraint check_b check (a = 1 and b < 45);
419 insert into mlparted values (1, 45, 'a');
420 ERROR: new row for relation "mlparted5a" violates check constraint "check_b"
421 DETAIL: Failing row contains (1, 45, a).
422 create function mlparted5abrtrig_func() returns trigger as $$ begin new.c = 'b'; return new; end; $$ language plpgsql;
423 create trigger mlparted5abrtrig before insert on mlparted5a for each row execute procedure mlparted5abrtrig_func();
424 insert into mlparted5 (a, b, c) values (1, 40, 'a');
425 ERROR: new row for relation "mlparted5a" violates partition constraint
426 DETAIL: Failing row contains (b, 1, 40).
427 drop table mlparted5;
428 -- check that message shown after failure to find a partition shows the
429 -- appropriate key description (or none) in various situations
430 create table key_desc (a int, b int) partition by list ((a+0));
431 create table key_desc_1 partition of key_desc for values in (1) partition by range (b);
432 create user someone_else;
433 grant select (a) on key_desc_1 to someone_else;
434 grant insert on key_desc to someone_else;
435 set role someone_else;
436 -- no key description is shown
437 insert into key_desc values (1, 1);
438 ERROR: no partition of relation "key_desc_1" found for row
440 grant select (b) on key_desc_1 to someone_else;
441 set role someone_else;
442 -- key description (b)=(1) is now shown
443 insert into key_desc values (1, 1);
444 ERROR: no partition of relation "key_desc_1" found for row
445 DETAIL: Partition key of the failing row contains (b) = (1).
446 -- key description is not shown if key contains expression
447 insert into key_desc values (2, 1);
448 ERROR: no partition of relation "key_desc" found for row
450 revoke all on key_desc from someone_else;
451 revoke all on key_desc_1 from someone_else;
452 drop role someone_else;
453 drop table key_desc, key_desc_1;
454 -- check multi-column range partitioning expression enforces the same
455 -- constraint as what tuple-routing would determine it to be
456 create table mcrparted (a int, b int, c int) partition by range (a, abs(b), c);
457 create table mcrparted0 partition of mcrparted for values from (minvalue, 0, 0) to (1, maxvalue, 0);
458 create table mcrparted1 partition of mcrparted for values from (2, 1, minvalue) to (10, 5, 10);
459 create table mcrparted2 partition of mcrparted for values from (10, 6, minvalue) to (10, maxvalue, 0);
460 create table mcrparted3 partition of mcrparted for values from (11, 1, 1) to (20, 10, 10);
461 create table mcrparted4 partition of mcrparted for values from (21, minvalue, 0) to (30, 20, maxvalue);
462 create table mcrparted5 partition of mcrparted for values from (30, 21, 20) to (maxvalue, 0, 0);
463 -- routed to mcrparted0
464 insert into mcrparted values (0, 1, 1);
465 insert into mcrparted0 values (0, 1, 1);
466 -- routed to mcparted1
467 insert into mcrparted values (9, 1000, 1);
468 insert into mcrparted1 values (9, 1000, 1);
469 insert into mcrparted values (10, 5, -1);
470 insert into mcrparted1 values (10, 5, -1);
471 insert into mcrparted values (2, 1, 0);
472 insert into mcrparted1 values (2, 1, 0);
473 -- routed to mcparted2
474 insert into mcrparted values (10, 6, 1000);
475 insert into mcrparted2 values (10, 6, 1000);
476 insert into mcrparted values (10, 1000, 1000);
477 insert into mcrparted2 values (10, 1000, 1000);
478 -- no partition exists, nor does mcrparted3 accept it
479 insert into mcrparted values (11, 1, -1);
480 ERROR: no partition of relation "mcrparted" found for row
481 DETAIL: Partition key of the failing row contains (a, abs(b), c) = (11, 1, -1).
482 insert into mcrparted3 values (11, 1, -1);
483 ERROR: new row for relation "mcrparted3" violates partition constraint
484 DETAIL: Failing row contains (11, 1, -1).
485 -- routed to mcrparted5
486 insert into mcrparted values (30, 21, 20);
487 insert into mcrparted5 values (30, 21, 20);
488 insert into mcrparted4 values (30, 21, 20); -- error
489 ERROR: new row for relation "mcrparted4" violates partition constraint
490 DETAIL: Failing row contains (30, 21, 20).
492 select tableoid::regclass::text, * from mcrparted order by 1;
494 ------------+----+------+------
495 mcrparted0 | 0 | 1 | 1
496 mcrparted0 | 0 | 1 | 1
497 mcrparted1 | 9 | 1000 | 1
498 mcrparted1 | 9 | 1000 | 1
499 mcrparted1 | 10 | 5 | -1
500 mcrparted1 | 10 | 5 | -1
501 mcrparted1 | 2 | 1 | 0
502 mcrparted1 | 2 | 1 | 0
503 mcrparted2 | 10 | 6 | 1000
504 mcrparted2 | 10 | 6 | 1000
505 mcrparted2 | 10 | 1000 | 1000
506 mcrparted2 | 10 | 1000 | 1000
507 mcrparted5 | 30 | 21 | 20
508 mcrparted5 | 30 | 21 | 20
512 drop table mcrparted;
513 -- check that a BR constraint can't make partition contain violating rows
514 create table brtrigpartcon (a int, b text) partition by list (a);
515 create table brtrigpartcon1 partition of brtrigpartcon for values in (1);
516 create or replace function brtrigpartcon1trigf() returns trigger as $$begin new.a := 2; return new; end$$ language plpgsql;
517 create trigger brtrigpartcon1trig before insert on brtrigpartcon1 for each row execute procedure brtrigpartcon1trigf();
518 insert into brtrigpartcon values (1, 'hi there');
519 ERROR: new row for relation "brtrigpartcon1" violates partition constraint
520 DETAIL: Failing row contains (2, hi there).
521 insert into brtrigpartcon1 values (1, 'hi there');
522 ERROR: new row for relation "brtrigpartcon1" violates partition constraint
523 DETAIL: Failing row contains (2, hi there).
524 -- check that the message shows the appropriate column description in a
525 -- situation where the partitioned table is not the primary ModifyTable node
526 create table inserttest3 (f1 text default 'foo', f2 text default 'bar', f3 int);
527 create role regress_coldesc_role;
528 grant insert on inserttest3 to regress_coldesc_role;
529 grant insert on brtrigpartcon to regress_coldesc_role;
530 revoke select on brtrigpartcon from regress_coldesc_role;
531 set role regress_coldesc_role;
532 with result as (insert into brtrigpartcon values (1, 'hi there') returning 1)
533 insert into inserttest3 (f3) select * from result;
534 ERROR: new row for relation "brtrigpartcon1" violates partition constraint
535 DETAIL: Failing row contains (a, b) = (2, hi there).
538 revoke all on inserttest3 from regress_coldesc_role;
539 revoke all on brtrigpartcon from regress_coldesc_role;
540 drop role regress_coldesc_role;
541 drop table inserttest3;
542 drop table brtrigpartcon;
543 drop function brtrigpartcon1trigf();
544 -- check multi-column range partitioning with minvalue/maxvalue constraints
545 create table mcrparted (a text, b int) partition by range(a, b);
546 create table mcrparted1_lt_b partition of mcrparted for values from (minvalue, 0) to ('b', minvalue);
547 create table mcrparted2_b partition of mcrparted for values from ('b', minvalue) to ('c', minvalue);
548 create table mcrparted3_c_to_common partition of mcrparted for values from ('c', minvalue) to ('common', minvalue);
549 create table mcrparted4_common_lt_0 partition of mcrparted for values from ('common', minvalue) to ('common', 0);
550 create table mcrparted5_common_0_to_10 partition of mcrparted for values from ('common', 0) to ('common', 10);
551 create table mcrparted6_common_ge_10 partition of mcrparted for values from ('common', 10) to ('common', maxvalue);
552 create table mcrparted7_gt_common_lt_d partition of mcrparted for values from ('common', maxvalue) to ('d', minvalue);
553 create table mcrparted8_ge_d partition of mcrparted for values from ('d', minvalue) to (maxvalue, 0);
555 Table "public.mcrparted"
556 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
557 --------+---------+-----------+----------+---------+----------+--------------+-------------
558 a | text | | | | extended | |
559 b | integer | | | | plain | |
560 Partition key: RANGE (a, b)
561 Partitions: mcrparted1_lt_b FOR VALUES FROM (MINVALUE, 0) TO ('b', MINVALUE),
562 mcrparted2_b FOR VALUES FROM ('b', MINVALUE) TO ('c', MINVALUE),
563 mcrparted3_c_to_common FOR VALUES FROM ('c', MINVALUE) TO ('common', MINVALUE),
564 mcrparted4_common_lt_0 FOR VALUES FROM ('common', MINVALUE) TO ('common', 0),
565 mcrparted5_common_0_to_10 FOR VALUES FROM ('common', 0) TO ('common', 10),
566 mcrparted6_common_ge_10 FOR VALUES FROM ('common', 10) TO ('common', MAXVALUE),
567 mcrparted7_gt_common_lt_d FOR VALUES FROM ('common', MAXVALUE) TO ('d', MINVALUE),
568 mcrparted8_ge_d FOR VALUES FROM ('d', MINVALUE) TO (MAXVALUE, 0)
571 Table "public.mcrparted1_lt_b"
572 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
573 --------+---------+-----------+----------+---------+----------+--------------+-------------
574 a | text | | | | extended | |
575 b | integer | | | | plain | |
576 Partition of: mcrparted FOR VALUES FROM (MINVALUE, 0) TO ('b', MINVALUE)
577 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a < 'b'::text))
580 Table "public.mcrparted2_b"
581 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
582 --------+---------+-----------+----------+---------+----------+--------------+-------------
583 a | text | | | | extended | |
584 b | integer | | | | plain | |
585 Partition of: mcrparted FOR VALUES FROM ('b', MINVALUE) TO ('c', MINVALUE)
586 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a >= 'b'::text) AND (a < 'c'::text))
588 \d+ mcrparted3_c_to_common
589 Table "public.mcrparted3_c_to_common"
590 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
591 --------+---------+-----------+----------+---------+----------+--------------+-------------
592 a | text | | | | extended | |
593 b | integer | | | | plain | |
594 Partition of: mcrparted FOR VALUES FROM ('c', MINVALUE) TO ('common', MINVALUE)
595 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a >= 'c'::text) AND (a < 'common'::text))
597 \d+ mcrparted4_common_lt_0
598 Table "public.mcrparted4_common_lt_0"
599 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
600 --------+---------+-----------+----------+---------+----------+--------------+-------------
601 a | text | | | | extended | |
602 b | integer | | | | plain | |
603 Partition of: mcrparted FOR VALUES FROM ('common', MINVALUE) TO ('common', 0)
604 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a = 'common'::text) AND (b < 0))
606 \d+ mcrparted5_common_0_to_10
607 Table "public.mcrparted5_common_0_to_10"
608 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
609 --------+---------+-----------+----------+---------+----------+--------------+-------------
610 a | text | | | | extended | |
611 b | integer | | | | plain | |
612 Partition of: mcrparted FOR VALUES FROM ('common', 0) TO ('common', 10)
613 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a = 'common'::text) AND (b >= 0) AND (b < 10))
615 \d+ mcrparted6_common_ge_10
616 Table "public.mcrparted6_common_ge_10"
617 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
618 --------+---------+-----------+----------+---------+----------+--------------+-------------
619 a | text | | | | extended | |
620 b | integer | | | | plain | |
621 Partition of: mcrparted FOR VALUES FROM ('common', 10) TO ('common', MAXVALUE)
622 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a = 'common'::text) AND (b >= 10))
624 \d+ mcrparted7_gt_common_lt_d
625 Table "public.mcrparted7_gt_common_lt_d"
626 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
627 --------+---------+-----------+----------+---------+----------+--------------+-------------
628 a | text | | | | extended | |
629 b | integer | | | | plain | |
630 Partition of: mcrparted FOR VALUES FROM ('common', MAXVALUE) TO ('d', MINVALUE)
631 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a > 'common'::text) AND (a < 'd'::text))
634 Table "public.mcrparted8_ge_d"
635 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
636 --------+---------+-----------+----------+---------+----------+--------------+-------------
637 a | text | | | | extended | |
638 b | integer | | | | plain | |
639 Partition of: mcrparted FOR VALUES FROM ('d', MINVALUE) TO (MAXVALUE, 0)
640 Partition constraint: ((a IS NOT NULL) AND (b IS NOT NULL) AND (a >= 'd'::text))
642 insert into mcrparted values ('aaa', 0), ('b', 0), ('bz', 10), ('c', -10),
643 ('comm', -10), ('common', -10), ('common', 0), ('common', 10),
644 ('commons', 0), ('d', -10), ('e', 0);
645 select tableoid::regclass, * from mcrparted order by a, b;
647 ---------------------------+---------+-----
648 mcrparted1_lt_b | aaa | 0
650 mcrparted2_b | bz | 10
651 mcrparted3_c_to_common | c | -10
652 mcrparted3_c_to_common | comm | -10
653 mcrparted4_common_lt_0 | common | -10
654 mcrparted5_common_0_to_10 | common | 0
655 mcrparted6_common_ge_10 | common | 10
656 mcrparted7_gt_common_lt_d | commons | 0
657 mcrparted8_ge_d | d | -10
658 mcrparted8_ge_d | e | 0
661 drop table mcrparted;
662 -- check that wholerow vars in the RETURNING list work with partitioned tables
663 create table returningwrtest (a int) partition by list (a);
664 create table returningwrtest1 partition of returningwrtest for values in (1);
665 insert into returningwrtest values (1) returning returningwrtest;
671 -- check also that the wholerow vars in RETURNING list are converted as needed
672 alter table returningwrtest add b text;
673 create table returningwrtest2 (b text, c int, a int);
674 alter table returningwrtest2 drop c;
675 alter table returningwrtest attach partition returningwrtest2 for values in (2);
676 insert into returningwrtest values (2, 'foo') returning returningwrtest;
682 drop table returningwrtest;