]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/inherit.out
Improve expression evaluation test coverage.
[postgresql] / src / test / regress / expected / inherit.out
1 --
2 -- Test inheritance features
3 --
4 CREATE TABLE a (aa TEXT);
5 CREATE TABLE b (bb TEXT) INHERITS (a);
6 CREATE TABLE c (cc TEXT) INHERITS (a);
7 CREATE TABLE d (dd TEXT) INHERITS (b,c,a);
8 NOTICE:  merging multiple inherited definitions of column "aa"
9 NOTICE:  merging multiple inherited definitions of column "aa"
10 INSERT INTO a(aa) VALUES('aaa');
11 INSERT INTO a(aa) VALUES('aaaa');
12 INSERT INTO a(aa) VALUES('aaaaa');
13 INSERT INTO a(aa) VALUES('aaaaaa');
14 INSERT INTO a(aa) VALUES('aaaaaaa');
15 INSERT INTO a(aa) VALUES('aaaaaaaa');
16 INSERT INTO b(aa) VALUES('bbb');
17 INSERT INTO b(aa) VALUES('bbbb');
18 INSERT INTO b(aa) VALUES('bbbbb');
19 INSERT INTO b(aa) VALUES('bbbbbb');
20 INSERT INTO b(aa) VALUES('bbbbbbb');
21 INSERT INTO b(aa) VALUES('bbbbbbbb');
22 INSERT INTO c(aa) VALUES('ccc');
23 INSERT INTO c(aa) VALUES('cccc');
24 INSERT INTO c(aa) VALUES('ccccc');
25 INSERT INTO c(aa) VALUES('cccccc');
26 INSERT INTO c(aa) VALUES('ccccccc');
27 INSERT INTO c(aa) VALUES('cccccccc');
28 INSERT INTO d(aa) VALUES('ddd');
29 INSERT INTO d(aa) VALUES('dddd');
30 INSERT INTO d(aa) VALUES('ddddd');
31 INSERT INTO d(aa) VALUES('dddddd');
32 INSERT INTO d(aa) VALUES('ddddddd');
33 INSERT INTO d(aa) VALUES('dddddddd');
34 SELECT relname, a.* FROM a, pg_class where a.tableoid = pg_class.oid;
35  relname |    aa    
36 ---------+----------
37  a       | aaa
38  a       | aaaa
39  a       | aaaaa
40  a       | aaaaaa
41  a       | aaaaaaa
42  a       | aaaaaaaa
43  b       | bbb
44  b       | bbbb
45  b       | bbbbb
46  b       | bbbbbb
47  b       | bbbbbbb
48  b       | bbbbbbbb
49  c       | ccc
50  c       | cccc
51  c       | ccccc
52  c       | cccccc
53  c       | ccccccc
54  c       | cccccccc
55  d       | ddd
56  d       | dddd
57  d       | ddddd
58  d       | dddddd
59  d       | ddddddd
60  d       | dddddddd
61 (24 rows)
62
63 SELECT relname, b.* FROM b, pg_class where b.tableoid = pg_class.oid;
64  relname |    aa    | bb 
65 ---------+----------+----
66  b       | bbb      | 
67  b       | bbbb     | 
68  b       | bbbbb    | 
69  b       | bbbbbb   | 
70  b       | bbbbbbb  | 
71  b       | bbbbbbbb | 
72  d       | ddd      | 
73  d       | dddd     | 
74  d       | ddddd    | 
75  d       | dddddd   | 
76  d       | ddddddd  | 
77  d       | dddddddd | 
78 (12 rows)
79
80 SELECT relname, c.* FROM c, pg_class where c.tableoid = pg_class.oid;
81  relname |    aa    | cc 
82 ---------+----------+----
83  c       | ccc      | 
84  c       | cccc     | 
85  c       | ccccc    | 
86  c       | cccccc   | 
87  c       | ccccccc  | 
88  c       | cccccccc | 
89  d       | ddd      | 
90  d       | dddd     | 
91  d       | ddddd    | 
92  d       | dddddd   | 
93  d       | ddddddd  | 
94  d       | dddddddd | 
95 (12 rows)
96
97 SELECT relname, d.* FROM d, pg_class where d.tableoid = pg_class.oid;
98  relname |    aa    | bb | cc | dd 
99 ---------+----------+----+----+----
100  d       | ddd      |    |    | 
101  d       | dddd     |    |    | 
102  d       | ddddd    |    |    | 
103  d       | dddddd   |    |    | 
104  d       | ddddddd  |    |    | 
105  d       | dddddddd |    |    | 
106 (6 rows)
107
108 SELECT relname, a.* FROM ONLY a, pg_class where a.tableoid = pg_class.oid;
109  relname |    aa    
110 ---------+----------
111  a       | aaa
112  a       | aaaa
113  a       | aaaaa
114  a       | aaaaaa
115  a       | aaaaaaa
116  a       | aaaaaaaa
117 (6 rows)
118
119 SELECT relname, b.* FROM ONLY b, pg_class where b.tableoid = pg_class.oid;
120  relname |    aa    | bb 
121 ---------+----------+----
122  b       | bbb      | 
123  b       | bbbb     | 
124  b       | bbbbb    | 
125  b       | bbbbbb   | 
126  b       | bbbbbbb  | 
127  b       | bbbbbbbb | 
128 (6 rows)
129
130 SELECT relname, c.* FROM ONLY c, pg_class where c.tableoid = pg_class.oid;
131  relname |    aa    | cc 
132 ---------+----------+----
133  c       | ccc      | 
134  c       | cccc     | 
135  c       | ccccc    | 
136  c       | cccccc   | 
137  c       | ccccccc  | 
138  c       | cccccccc | 
139 (6 rows)
140
141 SELECT relname, d.* FROM ONLY d, pg_class where d.tableoid = pg_class.oid;
142  relname |    aa    | bb | cc | dd 
143 ---------+----------+----+----+----
144  d       | ddd      |    |    | 
145  d       | dddd     |    |    | 
146  d       | ddddd    |    |    | 
147  d       | dddddd   |    |    | 
148  d       | ddddddd  |    |    | 
149  d       | dddddddd |    |    | 
150 (6 rows)
151
152 UPDATE a SET aa='zzzz' WHERE aa='aaaa';
153 UPDATE ONLY a SET aa='zzzzz' WHERE aa='aaaaa';
154 UPDATE b SET aa='zzz' WHERE aa='aaa';
155 UPDATE ONLY b SET aa='zzz' WHERE aa='aaa';
156 UPDATE a SET aa='zzzzzz' WHERE aa LIKE 'aaa%';
157 SELECT relname, a.* FROM a, pg_class where a.tableoid = pg_class.oid;
158  relname |    aa    
159 ---------+----------
160  a       | zzzz
161  a       | zzzzz
162  a       | zzzzzz
163  a       | zzzzzz
164  a       | zzzzzz
165  a       | zzzzzz
166  b       | bbb
167  b       | bbbb
168  b       | bbbbb
169  b       | bbbbbb
170  b       | bbbbbbb
171  b       | bbbbbbbb
172  c       | ccc
173  c       | cccc
174  c       | ccccc
175  c       | cccccc
176  c       | ccccccc
177  c       | cccccccc
178  d       | ddd
179  d       | dddd
180  d       | ddddd
181  d       | dddddd
182  d       | ddddddd
183  d       | dddddddd
184 (24 rows)
185
186 SELECT relname, b.* FROM b, pg_class where b.tableoid = pg_class.oid;
187  relname |    aa    | bb 
188 ---------+----------+----
189  b       | bbb      | 
190  b       | bbbb     | 
191  b       | bbbbb    | 
192  b       | bbbbbb   | 
193  b       | bbbbbbb  | 
194  b       | bbbbbbbb | 
195  d       | ddd      | 
196  d       | dddd     | 
197  d       | ddddd    | 
198  d       | dddddd   | 
199  d       | ddddddd  | 
200  d       | dddddddd | 
201 (12 rows)
202
203 SELECT relname, c.* FROM c, pg_class where c.tableoid = pg_class.oid;
204  relname |    aa    | cc 
205 ---------+----------+----
206  c       | ccc      | 
207  c       | cccc     | 
208  c       | ccccc    | 
209  c       | cccccc   | 
210  c       | ccccccc  | 
211  c       | cccccccc | 
212  d       | ddd      | 
213  d       | dddd     | 
214  d       | ddddd    | 
215  d       | dddddd   | 
216  d       | ddddddd  | 
217  d       | dddddddd | 
218 (12 rows)
219
220 SELECT relname, d.* FROM d, pg_class where d.tableoid = pg_class.oid;
221  relname |    aa    | bb | cc | dd 
222 ---------+----------+----+----+----
223  d       | ddd      |    |    | 
224  d       | dddd     |    |    | 
225  d       | ddddd    |    |    | 
226  d       | dddddd   |    |    | 
227  d       | ddddddd  |    |    | 
228  d       | dddddddd |    |    | 
229 (6 rows)
230
231 SELECT relname, a.* FROM ONLY a, pg_class where a.tableoid = pg_class.oid;
232  relname |   aa   
233 ---------+--------
234  a       | zzzz
235  a       | zzzzz
236  a       | zzzzzz
237  a       | zzzzzz
238  a       | zzzzzz
239  a       | zzzzzz
240 (6 rows)
241
242 SELECT relname, b.* FROM ONLY b, pg_class where b.tableoid = pg_class.oid;
243  relname |    aa    | bb 
244 ---------+----------+----
245  b       | bbb      | 
246  b       | bbbb     | 
247  b       | bbbbb    | 
248  b       | bbbbbb   | 
249  b       | bbbbbbb  | 
250  b       | bbbbbbbb | 
251 (6 rows)
252
253 SELECT relname, c.* FROM ONLY c, pg_class where c.tableoid = pg_class.oid;
254  relname |    aa    | cc 
255 ---------+----------+----
256  c       | ccc      | 
257  c       | cccc     | 
258  c       | ccccc    | 
259  c       | cccccc   | 
260  c       | ccccccc  | 
261  c       | cccccccc | 
262 (6 rows)
263
264 SELECT relname, d.* FROM ONLY d, pg_class where d.tableoid = pg_class.oid;
265  relname |    aa    | bb | cc | dd 
266 ---------+----------+----+----+----
267  d       | ddd      |    |    | 
268  d       | dddd     |    |    | 
269  d       | ddddd    |    |    | 
270  d       | dddddd   |    |    | 
271  d       | ddddddd  |    |    | 
272  d       | dddddddd |    |    | 
273 (6 rows)
274
275 UPDATE b SET aa='new';
276 SELECT relname, a.* FROM a, pg_class where a.tableoid = pg_class.oid;
277  relname |    aa    
278 ---------+----------
279  a       | zzzz
280  a       | zzzzz
281  a       | zzzzzz
282  a       | zzzzzz
283  a       | zzzzzz
284  a       | zzzzzz
285  b       | new
286  b       | new
287  b       | new
288  b       | new
289  b       | new
290  b       | new
291  c       | ccc
292  c       | cccc
293  c       | ccccc
294  c       | cccccc
295  c       | ccccccc
296  c       | cccccccc
297  d       | new
298  d       | new
299  d       | new
300  d       | new
301  d       | new
302  d       | new
303 (24 rows)
304
305 SELECT relname, b.* FROM b, pg_class where b.tableoid = pg_class.oid;
306  relname | aa  | bb 
307 ---------+-----+----
308  b       | new | 
309  b       | new | 
310  b       | new | 
311  b       | new | 
312  b       | new | 
313  b       | new | 
314  d       | new | 
315  d       | new | 
316  d       | new | 
317  d       | new | 
318  d       | new | 
319  d       | new | 
320 (12 rows)
321
322 SELECT relname, c.* FROM c, pg_class where c.tableoid = pg_class.oid;
323  relname |    aa    | cc 
324 ---------+----------+----
325  c       | ccc      | 
326  c       | cccc     | 
327  c       | ccccc    | 
328  c       | cccccc   | 
329  c       | ccccccc  | 
330  c       | cccccccc | 
331  d       | new      | 
332  d       | new      | 
333  d       | new      | 
334  d       | new      | 
335  d       | new      | 
336  d       | new      | 
337 (12 rows)
338
339 SELECT relname, d.* FROM d, pg_class where d.tableoid = pg_class.oid;
340  relname | aa  | bb | cc | dd 
341 ---------+-----+----+----+----
342  d       | new |    |    | 
343  d       | new |    |    | 
344  d       | new |    |    | 
345  d       | new |    |    | 
346  d       | new |    |    | 
347  d       | new |    |    | 
348 (6 rows)
349
350 SELECT relname, a.* FROM ONLY a, pg_class where a.tableoid = pg_class.oid;
351  relname |   aa   
352 ---------+--------
353  a       | zzzz
354  a       | zzzzz
355  a       | zzzzzz
356  a       | zzzzzz
357  a       | zzzzzz
358  a       | zzzzzz
359 (6 rows)
360
361 SELECT relname, b.* FROM ONLY b, pg_class where b.tableoid = pg_class.oid;
362  relname | aa  | bb 
363 ---------+-----+----
364  b       | new | 
365  b       | new | 
366  b       | new | 
367  b       | new | 
368  b       | new | 
369  b       | new | 
370 (6 rows)
371
372 SELECT relname, c.* FROM ONLY c, pg_class where c.tableoid = pg_class.oid;
373  relname |    aa    | cc 
374 ---------+----------+----
375  c       | ccc      | 
376  c       | cccc     | 
377  c       | ccccc    | 
378  c       | cccccc   | 
379  c       | ccccccc  | 
380  c       | cccccccc | 
381 (6 rows)
382
383 SELECT relname, d.* FROM ONLY d, pg_class where d.tableoid = pg_class.oid;
384  relname | aa  | bb | cc | dd 
385 ---------+-----+----+----+----
386  d       | new |    |    | 
387  d       | new |    |    | 
388  d       | new |    |    | 
389  d       | new |    |    | 
390  d       | new |    |    | 
391  d       | new |    |    | 
392 (6 rows)
393
394 UPDATE a SET aa='new';
395 DELETE FROM ONLY c WHERE aa='new';
396 SELECT relname, a.* FROM a, pg_class where a.tableoid = pg_class.oid;
397  relname | aa  
398 ---------+-----
399  a       | new
400  a       | new
401  a       | new
402  a       | new
403  a       | new
404  a       | new
405  b       | new
406  b       | new
407  b       | new
408  b       | new
409  b       | new
410  b       | new
411  d       | new
412  d       | new
413  d       | new
414  d       | new
415  d       | new
416  d       | new
417 (18 rows)
418
419 SELECT relname, b.* FROM b, pg_class where b.tableoid = pg_class.oid;
420  relname | aa  | bb 
421 ---------+-----+----
422  b       | new | 
423  b       | new | 
424  b       | new | 
425  b       | new | 
426  b       | new | 
427  b       | new | 
428  d       | new | 
429  d       | new | 
430  d       | new | 
431  d       | new | 
432  d       | new | 
433  d       | new | 
434 (12 rows)
435
436 SELECT relname, c.* FROM c, pg_class where c.tableoid = pg_class.oid;
437  relname | aa  | cc 
438 ---------+-----+----
439  d       | new | 
440  d       | new | 
441  d       | new | 
442  d       | new | 
443  d       | new | 
444  d       | new | 
445 (6 rows)
446
447 SELECT relname, d.* FROM d, pg_class where d.tableoid = pg_class.oid;
448  relname | aa  | bb | cc | dd 
449 ---------+-----+----+----+----
450  d       | new |    |    | 
451  d       | new |    |    | 
452  d       | new |    |    | 
453  d       | new |    |    | 
454  d       | new |    |    | 
455  d       | new |    |    | 
456 (6 rows)
457
458 SELECT relname, a.* FROM ONLY a, pg_class where a.tableoid = pg_class.oid;
459  relname | aa  
460 ---------+-----
461  a       | new
462  a       | new
463  a       | new
464  a       | new
465  a       | new
466  a       | new
467 (6 rows)
468
469 SELECT relname, b.* FROM ONLY b, pg_class where b.tableoid = pg_class.oid;
470  relname | aa  | bb 
471 ---------+-----+----
472  b       | new | 
473  b       | new | 
474  b       | new | 
475  b       | new | 
476  b       | new | 
477  b       | new | 
478 (6 rows)
479
480 SELECT relname, c.* FROM ONLY c, pg_class where c.tableoid = pg_class.oid;
481  relname | aa | cc 
482 ---------+----+----
483 (0 rows)
484
485 SELECT relname, d.* FROM ONLY d, pg_class where d.tableoid = pg_class.oid;
486  relname | aa  | bb | cc | dd 
487 ---------+-----+----+----+----
488  d       | new |    |    | 
489  d       | new |    |    | 
490  d       | new |    |    | 
491  d       | new |    |    | 
492  d       | new |    |    | 
493  d       | new |    |    | 
494 (6 rows)
495
496 DELETE FROM a;
497 SELECT relname, a.* FROM a, pg_class where a.tableoid = pg_class.oid;
498  relname | aa 
499 ---------+----
500 (0 rows)
501
502 SELECT relname, b.* FROM b, pg_class where b.tableoid = pg_class.oid;
503  relname | aa | bb 
504 ---------+----+----
505 (0 rows)
506
507 SELECT relname, c.* FROM c, pg_class where c.tableoid = pg_class.oid;
508  relname | aa | cc 
509 ---------+----+----
510 (0 rows)
511
512 SELECT relname, d.* FROM d, pg_class where d.tableoid = pg_class.oid;
513  relname | aa | bb | cc | dd 
514 ---------+----+----+----+----
515 (0 rows)
516
517 SELECT relname, a.* FROM ONLY a, pg_class where a.tableoid = pg_class.oid;
518  relname | aa 
519 ---------+----
520 (0 rows)
521
522 SELECT relname, b.* FROM ONLY b, pg_class where b.tableoid = pg_class.oid;
523  relname | aa | bb 
524 ---------+----+----
525 (0 rows)
526
527 SELECT relname, c.* FROM ONLY c, pg_class where c.tableoid = pg_class.oid;
528  relname | aa | cc 
529 ---------+----+----
530 (0 rows)
531
532 SELECT relname, d.* FROM ONLY d, pg_class where d.tableoid = pg_class.oid;
533  relname | aa | bb | cc | dd 
534 ---------+----+----+----+----
535 (0 rows)
536
537 -- Confirm PRIMARY KEY adds NOT NULL constraint to child table
538 CREATE TEMP TABLE z (b TEXT, PRIMARY KEY(aa, b)) inherits (a);
539 INSERT INTO z VALUES (NULL, 'text'); -- should fail
540 ERROR:  null value in column "aa" violates not-null constraint
541 DETAIL:  Failing row contains (null, text).
542 -- Check UPDATE with inherited target and an inherited source table
543 create temp table foo(f1 int, f2 int);
544 create temp table foo2(f3 int) inherits (foo);
545 create temp table bar(f1 int, f2 int);
546 create temp table bar2(f3 int) inherits (bar);
547 insert into foo values(1,1);
548 insert into foo values(3,3);
549 insert into foo2 values(2,2,2);
550 insert into foo2 values(3,3,3);
551 insert into bar values(1,1);
552 insert into bar values(2,2);
553 insert into bar values(3,3);
554 insert into bar values(4,4);
555 insert into bar2 values(1,1,1);
556 insert into bar2 values(2,2,2);
557 insert into bar2 values(3,3,3);
558 insert into bar2 values(4,4,4);
559 update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
560 select tableoid::regclass::text as relname, bar.* from bar order by 1,2;
561  relname | f1 | f2  
562 ---------+----+-----
563  bar     |  1 | 101
564  bar     |  2 | 102
565  bar     |  3 | 103
566  bar     |  4 |   4
567  bar2    |  1 | 101
568  bar2    |  2 | 102
569  bar2    |  3 | 103
570  bar2    |  4 |   4
571 (8 rows)
572
573 -- Check UPDATE with inherited target and an appendrel subquery
574 update bar set f2 = f2 + 100
575 from
576   ( select f1 from foo union all select f1+3 from foo ) ss
577 where bar.f1 = ss.f1;
578 select tableoid::regclass::text as relname, bar.* from bar order by 1,2;
579  relname | f1 | f2  
580 ---------+----+-----
581  bar     |  1 | 201
582  bar     |  2 | 202
583  bar     |  3 | 203
584  bar     |  4 | 104
585  bar2    |  1 | 201
586  bar2    |  2 | 202
587  bar2    |  3 | 203
588  bar2    |  4 | 104
589 (8 rows)
590
591 /* Test multiple inheritance of column defaults */
592 CREATE TABLE firstparent (tomorrow date default now()::date + 1);
593 CREATE TABLE secondparent (tomorrow date default  now() :: date  +  1);
594 CREATE TABLE jointchild () INHERITS (firstparent, secondparent);  -- ok
595 NOTICE:  merging multiple inherited definitions of column "tomorrow"
596 CREATE TABLE thirdparent (tomorrow date default now()::date - 1);
597 CREATE TABLE otherchild () INHERITS (firstparent, thirdparent);  -- not ok
598 NOTICE:  merging multiple inherited definitions of column "tomorrow"
599 ERROR:  column "tomorrow" inherits conflicting default values
600 HINT:  To resolve the conflict, specify a default explicitly.
601 CREATE TABLE otherchild (tomorrow date default now())
602   INHERITS (firstparent, thirdparent);  -- ok, child resolves ambiguous default
603 NOTICE:  merging multiple inherited definitions of column "tomorrow"
604 NOTICE:  merging column "tomorrow" with inherited definition
605 DROP TABLE firstparent, secondparent, jointchild, thirdparent, otherchild;
606 -- Test changing the type of inherited columns
607 insert into d values('test','one','two','three');
608 alter table a alter column aa type integer using bit_length(aa);
609 select * from d;
610  aa | bb  | cc  |  dd   
611 ----+-----+-----+-------
612  32 | one | two | three
613 (1 row)
614
615 -- check that oid column is handled properly during alter table inherit
616 create table oid_parent (a int) with oids;
617 create table oid_child () inherits (oid_parent);
618 select attinhcount, attislocal from pg_attribute
619   where attrelid = 'oid_child'::regclass and attname = 'oid';
620  attinhcount | attislocal 
621 -------------+------------
622            1 | f
623 (1 row)
624
625 drop table oid_child;
626 create table oid_child (a int) without oids;
627 alter table oid_child inherit oid_parent;  -- fail
628 ERROR:  table "oid_child" without OIDs cannot inherit from table "oid_parent" with OIDs
629 alter table oid_child set with oids;
630 select attinhcount, attislocal from pg_attribute
631   where attrelid = 'oid_child'::regclass and attname = 'oid';
632  attinhcount | attislocal 
633 -------------+------------
634            0 | t
635 (1 row)
636
637 alter table oid_child inherit oid_parent;
638 select attinhcount, attislocal from pg_attribute
639   where attrelid = 'oid_child'::regclass and attname = 'oid';
640  attinhcount | attislocal 
641 -------------+------------
642            1 | t
643 (1 row)
644
645 alter table oid_child set without oids;  -- fail
646 ERROR:  cannot drop inherited column "oid"
647 alter table oid_parent set without oids;
648 select attinhcount, attislocal from pg_attribute
649   where attrelid = 'oid_child'::regclass and attname = 'oid';
650  attinhcount | attislocal 
651 -------------+------------
652            0 | t
653 (1 row)
654
655 alter table oid_child set without oids;
656 select attinhcount, attislocal from pg_attribute
657   where attrelid = 'oid_child'::regclass and attname = 'oid';
658  attinhcount | attislocal 
659 -------------+------------
660 (0 rows)
661
662 drop table oid_parent cascade;
663 NOTICE:  drop cascades to table oid_child
664 -- Test non-inheritable parent constraints
665 create table p1(ff1 int);
666 alter table p1 add constraint p1chk check (ff1 > 0) no inherit;
667 alter table p1 add constraint p2chk check (ff1 > 10);
668 -- connoinherit should be true for NO INHERIT constraint
669 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.connoinherit from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname = 'p1' order by 1,2;
670  relname | conname | contype | conislocal | coninhcount | connoinherit 
671 ---------+---------+---------+------------+-------------+--------------
672  p1      | p1chk   | c       | t          |           0 | t
673  p1      | p2chk   | c       | t          |           0 | f
674 (2 rows)
675
676 -- Test that child does not inherit NO INHERIT constraints
677 create table c1 () inherits (p1);
678 \d p1
679                  Table "public.p1"
680  Column |  Type   | Collation | Nullable | Default 
681 --------+---------+-----------+----------+---------
682  ff1    | integer |           |          | 
683 Check constraints:
684     "p1chk" CHECK (ff1 > 0) NO INHERIT
685     "p2chk" CHECK (ff1 > 10)
686 Number of child tables: 1 (Use \d+ to list them.)
687
688 \d c1
689                  Table "public.c1"
690  Column |  Type   | Collation | Nullable | Default 
691 --------+---------+-----------+----------+---------
692  ff1    | integer |           |          | 
693 Check constraints:
694     "p2chk" CHECK (ff1 > 10)
695 Inherits: p1
696
697 -- Test that child does not override inheritable constraints of the parent
698 create table c2 (constraint p2chk check (ff1 > 10) no inherit) inherits (p1);   --fails
699 ERROR:  constraint "p2chk" conflicts with inherited constraint on relation "c2"
700 drop table p1 cascade;
701 NOTICE:  drop cascades to table c1
702 -- Tests for casting between the rowtypes of parent and child
703 -- tables. See the pgsql-hackers thread beginning Dec. 4/04
704 create table base (i integer);
705 create table derived () inherits (base);
706 insert into derived (i) values (0);
707 select derived::base from derived;
708  derived 
709 ---------
710  (0)
711 (1 row)
712
713 select NULL::derived::base;
714  base 
715 ------
716  
717 (1 row)
718
719 drop table derived;
720 drop table base;
721 create table p1(ff1 int);
722 create table p2(f1 text);
723 create function p2text(p2) returns text as 'select $1.f1' language sql;
724 create table c1(f3 int) inherits(p1,p2);
725 insert into c1 values(123456789, 'hi', 42);
726 select p2text(c1.*) from c1;
727  p2text 
728 --------
729  hi
730 (1 row)
731
732 drop function p2text(p2);
733 drop table c1;
734 drop table p2;
735 drop table p1;
736 CREATE TABLE ac (aa TEXT);
737 alter table ac add constraint ac_check check (aa is not null);
738 CREATE TABLE bc (bb TEXT) INHERITS (ac);
739 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
740  relname | conname  | contype | conislocal | coninhcount |      consrc      
741 ---------+----------+---------+------------+-------------+------------------
742  ac      | ac_check | c       | t          |           0 | (aa IS NOT NULL)
743  bc      | ac_check | c       | f          |           1 | (aa IS NOT NULL)
744 (2 rows)
745
746 insert into ac (aa) values (NULL);
747 ERROR:  new row for relation "ac" violates check constraint "ac_check"
748 DETAIL:  Failing row contains (null).
749 insert into bc (aa) values (NULL);
750 ERROR:  new row for relation "bc" violates check constraint "ac_check"
751 DETAIL:  Failing row contains (null, null).
752 alter table bc drop constraint ac_check;  -- fail, disallowed
753 ERROR:  cannot drop inherited constraint "ac_check" of relation "bc"
754 alter table ac drop constraint ac_check;
755 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
756  relname | conname | contype | conislocal | coninhcount | consrc 
757 ---------+---------+---------+------------+-------------+--------
758 (0 rows)
759
760 -- try the unnamed-constraint case
761 alter table ac add check (aa is not null);
762 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
763  relname |   conname   | contype | conislocal | coninhcount |      consrc      
764 ---------+-------------+---------+------------+-------------+------------------
765  ac      | ac_aa_check | c       | t          |           0 | (aa IS NOT NULL)
766  bc      | ac_aa_check | c       | f          |           1 | (aa IS NOT NULL)
767 (2 rows)
768
769 insert into ac (aa) values (NULL);
770 ERROR:  new row for relation "ac" violates check constraint "ac_aa_check"
771 DETAIL:  Failing row contains (null).
772 insert into bc (aa) values (NULL);
773 ERROR:  new row for relation "bc" violates check constraint "ac_aa_check"
774 DETAIL:  Failing row contains (null, null).
775 alter table bc drop constraint ac_aa_check;  -- fail, disallowed
776 ERROR:  cannot drop inherited constraint "ac_aa_check" of relation "bc"
777 alter table ac drop constraint ac_aa_check;
778 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
779  relname | conname | contype | conislocal | coninhcount | consrc 
780 ---------+---------+---------+------------+-------------+--------
781 (0 rows)
782
783 alter table ac add constraint ac_check check (aa is not null);
784 alter table bc no inherit ac;
785 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
786  relname | conname  | contype | conislocal | coninhcount |      consrc      
787 ---------+----------+---------+------------+-------------+------------------
788  ac      | ac_check | c       | t          |           0 | (aa IS NOT NULL)
789  bc      | ac_check | c       | t          |           0 | (aa IS NOT NULL)
790 (2 rows)
791
792 alter table bc drop constraint ac_check;
793 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
794  relname | conname  | contype | conislocal | coninhcount |      consrc      
795 ---------+----------+---------+------------+-------------+------------------
796  ac      | ac_check | c       | t          |           0 | (aa IS NOT NULL)
797 (1 row)
798
799 alter table ac drop constraint ac_check;
800 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
801  relname | conname | contype | conislocal | coninhcount | consrc 
802 ---------+---------+---------+------------+-------------+--------
803 (0 rows)
804
805 drop table bc;
806 drop table ac;
807 create table ac (a int constraint check_a check (a <> 0));
808 create table bc (a int constraint check_a check (a <> 0), b int constraint check_b check (b <> 0)) inherits (ac);
809 NOTICE:  merging column "a" with inherited definition
810 NOTICE:  merging constraint "check_a" with inherited definition
811 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc') order by 1,2;
812  relname | conname | contype | conislocal | coninhcount |  consrc  
813 ---------+---------+---------+------------+-------------+----------
814  ac      | check_a | c       | t          |           0 | (a <> 0)
815  bc      | check_a | c       | t          |           1 | (a <> 0)
816  bc      | check_b | c       | t          |           0 | (b <> 0)
817 (3 rows)
818
819 drop table bc;
820 drop table ac;
821 create table ac (a int constraint check_a check (a <> 0));
822 create table bc (b int constraint check_b check (b <> 0));
823 create table cc (c int constraint check_c check (c <> 0)) inherits (ac, bc);
824 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2;
825  relname | conname | contype | conislocal | coninhcount |  consrc  
826 ---------+---------+---------+------------+-------------+----------
827  ac      | check_a | c       | t          |           0 | (a <> 0)
828  bc      | check_b | c       | t          |           0 | (b <> 0)
829  cc      | check_a | c       | f          |           1 | (a <> 0)
830  cc      | check_b | c       | f          |           1 | (b <> 0)
831  cc      | check_c | c       | t          |           0 | (c <> 0)
832 (5 rows)
833
834 alter table cc no inherit bc;
835 select pc.relname, pgc.conname, pgc.contype, pgc.conislocal, pgc.coninhcount, pgc.consrc from pg_class as pc inner join pg_constraint as pgc on (pgc.conrelid = pc.oid) where pc.relname in ('ac', 'bc', 'cc') order by 1,2;
836  relname | conname | contype | conislocal | coninhcount |  consrc  
837 ---------+---------+---------+------------+-------------+----------
838  ac      | check_a | c       | t          |           0 | (a <> 0)
839  bc      | check_b | c       | t          |           0 | (b <> 0)
840  cc      | check_a | c       | f          |           1 | (a <> 0)
841  cc      | check_b | c       | t          |           0 | (b <> 0)
842  cc      | check_c | c       | t          |           0 | (c <> 0)
843 (5 rows)
844
845 drop table cc;
846 drop table bc;
847 drop table ac;
848 create table p1(f1 int);
849 create table p2(f2 int);
850 create table c1(f3 int) inherits(p1,p2);
851 insert into c1 values(1,-1,2);
852 alter table p2 add constraint cc check (f2>0);  -- fail
853 ERROR:  check constraint "cc" is violated by some row
854 alter table p2 add check (f2>0);  -- check it without a name, too
855 ERROR:  check constraint "p2_f2_check" is violated by some row
856 delete from c1;
857 insert into c1 values(1,1,2);
858 alter table p2 add check (f2>0);
859 insert into c1 values(1,-1,2);  -- fail
860 ERROR:  new row for relation "c1" violates check constraint "p2_f2_check"
861 DETAIL:  Failing row contains (1, -1, 2).
862 create table c2(f3 int) inherits(p1,p2);
863 \d c2
864                  Table "public.c2"
865  Column |  Type   | Collation | Nullable | Default 
866 --------+---------+-----------+----------+---------
867  f1     | integer |           |          | 
868  f2     | integer |           |          | 
869  f3     | integer |           |          | 
870 Check constraints:
871     "p2_f2_check" CHECK (f2 > 0)
872 Inherits: p1,
873           p2
874
875 create table c3 (f4 int) inherits(c1,c2);
876 NOTICE:  merging multiple inherited definitions of column "f1"
877 NOTICE:  merging multiple inherited definitions of column "f2"
878 NOTICE:  merging multiple inherited definitions of column "f3"
879 \d c3
880                  Table "public.c3"
881  Column |  Type   | Collation | Nullable | Default 
882 --------+---------+-----------+----------+---------
883  f1     | integer |           |          | 
884  f2     | integer |           |          | 
885  f3     | integer |           |          | 
886  f4     | integer |           |          | 
887 Check constraints:
888     "p2_f2_check" CHECK (f2 > 0)
889 Inherits: c1,
890           c2
891
892 drop table p1 cascade;
893 NOTICE:  drop cascades to 3 other objects
894 DETAIL:  drop cascades to table c1
895 drop cascades to table c2
896 drop cascades to table c3
897 drop table p2 cascade;
898 create table pp1 (f1 int);
899 create table cc1 (f2 text, f3 int) inherits (pp1);
900 alter table pp1 add column a1 int check (a1 > 0);
901 \d cc1
902                 Table "public.cc1"
903  Column |  Type   | Collation | Nullable | Default 
904 --------+---------+-----------+----------+---------
905  f1     | integer |           |          | 
906  f2     | text    |           |          | 
907  f3     | integer |           |          | 
908  a1     | integer |           |          | 
909 Check constraints:
910     "pp1_a1_check" CHECK (a1 > 0)
911 Inherits: pp1
912
913 create table cc2(f4 float) inherits(pp1,cc1);
914 NOTICE:  merging multiple inherited definitions of column "f1"
915 NOTICE:  merging multiple inherited definitions of column "a1"
916 \d cc2
917                      Table "public.cc2"
918  Column |       Type       | Collation | Nullable | Default 
919 --------+------------------+-----------+----------+---------
920  f1     | integer          |           |          | 
921  a1     | integer          |           |          | 
922  f2     | text             |           |          | 
923  f3     | integer          |           |          | 
924  f4     | double precision |           |          | 
925 Check constraints:
926     "pp1_a1_check" CHECK (a1 > 0)
927 Inherits: pp1,
928           cc1
929
930 alter table pp1 add column a2 int check (a2 > 0);
931 NOTICE:  merging definition of column "a2" for child "cc2"
932 NOTICE:  merging constraint "pp1_a2_check" with inherited definition
933 \d cc2
934                      Table "public.cc2"
935  Column |       Type       | Collation | Nullable | Default 
936 --------+------------------+-----------+----------+---------
937  f1     | integer          |           |          | 
938  a1     | integer          |           |          | 
939  f2     | text             |           |          | 
940  f3     | integer          |           |          | 
941  f4     | double precision |           |          | 
942  a2     | integer          |           |          | 
943 Check constraints:
944     "pp1_a1_check" CHECK (a1 > 0)
945     "pp1_a2_check" CHECK (a2 > 0)
946 Inherits: pp1,
947           cc1
948
949 drop table pp1 cascade;
950 NOTICE:  drop cascades to 2 other objects
951 DETAIL:  drop cascades to table cc1
952 drop cascades to table cc2
953 -- Test for renaming in simple multiple inheritance
954 CREATE TABLE inht1 (a int, b int);
955 CREATE TABLE inhs1 (b int, c int);
956 CREATE TABLE inhts (d int) INHERITS (inht1, inhs1);
957 NOTICE:  merging multiple inherited definitions of column "b"
958 ALTER TABLE inht1 RENAME a TO aa;
959 ALTER TABLE inht1 RENAME b TO bb;                -- to be failed
960 ERROR:  cannot rename inherited column "b"
961 ALTER TABLE inhts RENAME aa TO aaa;      -- to be failed
962 ERROR:  cannot rename inherited column "aa"
963 ALTER TABLE inhts RENAME d TO dd;
964 \d+ inhts
965                                    Table "public.inhts"
966  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
967 --------+---------+-----------+----------+---------+---------+--------------+-------------
968  aa     | integer |           |          |         | plain   |              | 
969  b      | integer |           |          |         | plain   |              | 
970  c      | integer |           |          |         | plain   |              | 
971  dd     | integer |           |          |         | plain   |              | 
972 Inherits: inht1,
973           inhs1
974
975 DROP TABLE inhts;
976 -- Test for renaming in diamond inheritance
977 CREATE TABLE inht2 (x int) INHERITS (inht1);
978 CREATE TABLE inht3 (y int) INHERITS (inht1);
979 CREATE TABLE inht4 (z int) INHERITS (inht2, inht3);
980 NOTICE:  merging multiple inherited definitions of column "aa"
981 NOTICE:  merging multiple inherited definitions of column "b"
982 ALTER TABLE inht1 RENAME aa TO aaa;
983 \d+ inht4
984                                    Table "public.inht4"
985  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
986 --------+---------+-----------+----------+---------+---------+--------------+-------------
987  aaa    | integer |           |          |         | plain   |              | 
988  b      | integer |           |          |         | plain   |              | 
989  x      | integer |           |          |         | plain   |              | 
990  y      | integer |           |          |         | plain   |              | 
991  z      | integer |           |          |         | plain   |              | 
992 Inherits: inht2,
993           inht3
994
995 CREATE TABLE inhts (d int) INHERITS (inht2, inhs1);
996 NOTICE:  merging multiple inherited definitions of column "b"
997 ALTER TABLE inht1 RENAME aaa TO aaaa;
998 ALTER TABLE inht1 RENAME b TO bb;                -- to be failed
999 ERROR:  cannot rename inherited column "b"
1000 \d+ inhts
1001                                    Table "public.inhts"
1002  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
1003 --------+---------+-----------+----------+---------+---------+--------------+-------------
1004  aaaa   | integer |           |          |         | plain   |              | 
1005  b      | integer |           |          |         | plain   |              | 
1006  x      | integer |           |          |         | plain   |              | 
1007  c      | integer |           |          |         | plain   |              | 
1008  d      | integer |           |          |         | plain   |              | 
1009 Inherits: inht2,
1010           inhs1
1011
1012 WITH RECURSIVE r AS (
1013   SELECT 'inht1'::regclass AS inhrelid
1014 UNION ALL
1015   SELECT c.inhrelid FROM pg_inherits c, r WHERE r.inhrelid = c.inhparent
1016 )
1017 SELECT a.attrelid::regclass, a.attname, a.attinhcount, e.expected
1018   FROM (SELECT inhrelid, count(*) AS expected FROM pg_inherits
1019         WHERE inhparent IN (SELECT inhrelid FROM r) GROUP BY inhrelid) e
1020   JOIN pg_attribute a ON e.inhrelid = a.attrelid WHERE NOT attislocal
1021   ORDER BY a.attrelid::regclass::name, a.attnum;
1022  attrelid | attname | attinhcount | expected 
1023 ----------+---------+-------------+----------
1024  inht2    | aaaa    |           1 |        1
1025  inht2    | b       |           1 |        1
1026  inht3    | aaaa    |           1 |        1
1027  inht3    | b       |           1 |        1
1028  inht4    | aaaa    |           2 |        2
1029  inht4    | b       |           2 |        2
1030  inht4    | x       |           1 |        2
1031  inht4    | y       |           1 |        2
1032  inhts    | aaaa    |           1 |        1
1033  inhts    | b       |           2 |        1
1034  inhts    | x       |           1 |        1
1035  inhts    | c       |           1 |        1
1036 (12 rows)
1037
1038 DROP TABLE inht1, inhs1 CASCADE;
1039 NOTICE:  drop cascades to 4 other objects
1040 DETAIL:  drop cascades to table inht2
1041 drop cascades to table inhts
1042 drop cascades to table inht3
1043 drop cascades to table inht4
1044 -- Test non-inheritable indices [UNIQUE, EXCLUDE] constraints
1045 CREATE TABLE test_constraints (id int, val1 varchar, val2 int, UNIQUE(val1, val2));
1046 CREATE TABLE test_constraints_inh () INHERITS (test_constraints);
1047 \d+ test_constraints
1048                                    Table "public.test_constraints"
1049  Column |       Type        | Collation | Nullable | Default | Storage  | Stats target | Description 
1050 --------+-------------------+-----------+----------+---------+----------+--------------+-------------
1051  id     | integer           |           |          |         | plain    |              | 
1052  val1   | character varying |           |          |         | extended |              | 
1053  val2   | integer           |           |          |         | plain    |              | 
1054 Indexes:
1055     "test_constraints_val1_val2_key" UNIQUE CONSTRAINT, btree (val1, val2)
1056 Child tables: test_constraints_inh
1057
1058 ALTER TABLE ONLY test_constraints DROP CONSTRAINT test_constraints_val1_val2_key;
1059 \d+ test_constraints
1060                                    Table "public.test_constraints"
1061  Column |       Type        | Collation | Nullable | Default | Storage  | Stats target | Description 
1062 --------+-------------------+-----------+----------+---------+----------+--------------+-------------
1063  id     | integer           |           |          |         | plain    |              | 
1064  val1   | character varying |           |          |         | extended |              | 
1065  val2   | integer           |           |          |         | plain    |              | 
1066 Child tables: test_constraints_inh
1067
1068 \d+ test_constraints_inh
1069                                  Table "public.test_constraints_inh"
1070  Column |       Type        | Collation | Nullable | Default | Storage  | Stats target | Description 
1071 --------+-------------------+-----------+----------+---------+----------+--------------+-------------
1072  id     | integer           |           |          |         | plain    |              | 
1073  val1   | character varying |           |          |         | extended |              | 
1074  val2   | integer           |           |          |         | plain    |              | 
1075 Inherits: test_constraints
1076
1077 DROP TABLE test_constraints_inh;
1078 DROP TABLE test_constraints;
1079 CREATE TABLE test_ex_constraints (
1080     c circle,
1081     EXCLUDE USING gist (c WITH &&)
1082 );
1083 CREATE TABLE test_ex_constraints_inh () INHERITS (test_ex_constraints);
1084 \d+ test_ex_constraints
1085                            Table "public.test_ex_constraints"
1086  Column |  Type  | Collation | Nullable | Default | Storage | Stats target | Description 
1087 --------+--------+-----------+----------+---------+---------+--------------+-------------
1088  c      | circle |           |          |         | plain   |              | 
1089 Indexes:
1090     "test_ex_constraints_c_excl" EXCLUDE USING gist (c WITH &&)
1091 Child tables: test_ex_constraints_inh
1092
1093 ALTER TABLE test_ex_constraints DROP CONSTRAINT test_ex_constraints_c_excl;
1094 \d+ test_ex_constraints
1095                            Table "public.test_ex_constraints"
1096  Column |  Type  | Collation | Nullable | Default | Storage | Stats target | Description 
1097 --------+--------+-----------+----------+---------+---------+--------------+-------------
1098  c      | circle |           |          |         | plain   |              | 
1099 Child tables: test_ex_constraints_inh
1100
1101 \d+ test_ex_constraints_inh
1102                          Table "public.test_ex_constraints_inh"
1103  Column |  Type  | Collation | Nullable | Default | Storage | Stats target | Description 
1104 --------+--------+-----------+----------+---------+---------+--------------+-------------
1105  c      | circle |           |          |         | plain   |              | 
1106 Inherits: test_ex_constraints
1107
1108 DROP TABLE test_ex_constraints_inh;
1109 DROP TABLE test_ex_constraints;
1110 -- Test non-inheritable foreign key constraints
1111 CREATE TABLE test_primary_constraints(id int PRIMARY KEY);
1112 CREATE TABLE test_foreign_constraints(id1 int REFERENCES test_primary_constraints(id));
1113 CREATE TABLE test_foreign_constraints_inh () INHERITS (test_foreign_constraints);
1114 \d+ test_primary_constraints
1115                          Table "public.test_primary_constraints"
1116  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
1117 --------+---------+-----------+----------+---------+---------+--------------+-------------
1118  id     | integer |           | not null |         | plain   |              | 
1119 Indexes:
1120     "test_primary_constraints_pkey" PRIMARY KEY, btree (id)
1121 Referenced by:
1122     TABLE "test_foreign_constraints" CONSTRAINT "test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
1123
1124 \d+ test_foreign_constraints
1125                          Table "public.test_foreign_constraints"
1126  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
1127 --------+---------+-----------+----------+---------+---------+--------------+-------------
1128  id1    | integer |           |          |         | plain   |              | 
1129 Foreign-key constraints:
1130     "test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
1131 Child tables: test_foreign_constraints_inh
1132
1133 ALTER TABLE test_foreign_constraints DROP CONSTRAINT test_foreign_constraints_id1_fkey;
1134 \d+ test_foreign_constraints
1135                          Table "public.test_foreign_constraints"
1136  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
1137 --------+---------+-----------+----------+---------+---------+--------------+-------------
1138  id1    | integer |           |          |         | plain   |              | 
1139 Child tables: test_foreign_constraints_inh
1140
1141 \d+ test_foreign_constraints_inh
1142                        Table "public.test_foreign_constraints_inh"
1143  Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description 
1144 --------+---------+-----------+----------+---------+---------+--------------+-------------
1145  id1    | integer |           |          |         | plain   |              | 
1146 Inherits: test_foreign_constraints
1147
1148 DROP TABLE test_foreign_constraints_inh;
1149 DROP TABLE test_foreign_constraints;
1150 DROP TABLE test_primary_constraints;
1151 -- Test that parent and child CHECK constraints can be created in either order
1152 create table p1(f1 int);
1153 create table p1_c1() inherits(p1);
1154 alter table p1 add constraint inh_check_constraint1 check (f1 > 0);
1155 alter table p1_c1 add constraint inh_check_constraint1 check (f1 > 0);
1156 NOTICE:  merging constraint "inh_check_constraint1" with inherited definition
1157 alter table p1_c1 add constraint inh_check_constraint2 check (f1 < 10);
1158 alter table p1 add constraint inh_check_constraint2 check (f1 < 10);
1159 NOTICE:  merging constraint "inh_check_constraint2" with inherited definition
1160 select conrelid::regclass::text as relname, conname, conislocal, coninhcount
1161 from pg_constraint where conname like 'inh\_check\_constraint%'
1162 order by 1, 2;
1163  relname |        conname        | conislocal | coninhcount 
1164 ---------+-----------------------+------------+-------------
1165  p1      | inh_check_constraint1 | t          |           0
1166  p1      | inh_check_constraint2 | t          |           0
1167  p1_c1   | inh_check_constraint1 | t          |           1
1168  p1_c1   | inh_check_constraint2 | t          |           1
1169 (4 rows)
1170
1171 drop table p1 cascade;
1172 NOTICE:  drop cascades to table p1_c1
1173 -- Test that a valid child can have not-valid parent, but not vice versa
1174 create table invalid_check_con(f1 int);
1175 create table invalid_check_con_child() inherits(invalid_check_con);
1176 alter table invalid_check_con_child add constraint inh_check_constraint check(f1 > 0) not valid;
1177 alter table invalid_check_con add constraint inh_check_constraint check(f1 > 0); -- fail
1178 ERROR:  constraint "inh_check_constraint" conflicts with NOT VALID constraint on relation "invalid_check_con_child"
1179 alter table invalid_check_con_child drop constraint inh_check_constraint;
1180 insert into invalid_check_con values(0);
1181 alter table invalid_check_con_child add constraint inh_check_constraint check(f1 > 0);
1182 alter table invalid_check_con add constraint inh_check_constraint check(f1 > 0) not valid;
1183 NOTICE:  merging constraint "inh_check_constraint" with inherited definition
1184 insert into invalid_check_con values(0); -- fail
1185 ERROR:  new row for relation "invalid_check_con" violates check constraint "inh_check_constraint"
1186 DETAIL:  Failing row contains (0).
1187 insert into invalid_check_con_child values(0); -- fail
1188 ERROR:  new row for relation "invalid_check_con_child" violates check constraint "inh_check_constraint"
1189 DETAIL:  Failing row contains (0).
1190 select conrelid::regclass::text as relname, conname,
1191        convalidated, conislocal, coninhcount, connoinherit
1192 from pg_constraint where conname like 'inh\_check\_constraint%'
1193 order by 1, 2;
1194          relname         |       conname        | convalidated | conislocal | coninhcount | connoinherit 
1195 -------------------------+----------------------+--------------+------------+-------------+--------------
1196  invalid_check_con       | inh_check_constraint | f            | t          |           0 | f
1197  invalid_check_con_child | inh_check_constraint | t            | t          |           1 | f
1198 (2 rows)
1199
1200 -- We don't drop the invalid_check_con* tables, to test dump/reload with
1201 --
1202 -- Test parameterized append plans for inheritance trees
1203 --
1204 create temp table patest0 (id, x) as
1205   select x, x from generate_series(0,1000) x;
1206 create temp table patest1() inherits (patest0);
1207 insert into patest1
1208   select x, x from generate_series(0,1000) x;
1209 create temp table patest2() inherits (patest0);
1210 insert into patest2
1211   select x, x from generate_series(0,1000) x;
1212 create index patest0i on patest0(id);
1213 create index patest1i on patest1(id);
1214 create index patest2i on patest2(id);
1215 analyze patest0;
1216 analyze patest1;
1217 analyze patest2;
1218 explain (costs off)
1219 select * from patest0 join (select f1 from int4_tbl limit 1) ss on id = f1;
1220                     QUERY PLAN                    
1221 --------------------------------------------------
1222  Nested Loop
1223    ->  Limit
1224          ->  Seq Scan on int4_tbl
1225    ->  Append
1226          ->  Index Scan using patest0i on patest0
1227                Index Cond: (id = int4_tbl.f1)
1228          ->  Index Scan using patest1i on patest1
1229                Index Cond: (id = int4_tbl.f1)
1230          ->  Index Scan using patest2i on patest2
1231                Index Cond: (id = int4_tbl.f1)
1232 (10 rows)
1233
1234 select * from patest0 join (select f1 from int4_tbl limit 1) ss on id = f1;
1235  id | x | f1 
1236 ----+---+----
1237   0 | 0 |  0
1238   0 | 0 |  0
1239   0 | 0 |  0
1240 (3 rows)
1241
1242 drop index patest2i;
1243 explain (costs off)
1244 select * from patest0 join (select f1 from int4_tbl limit 1) ss on id = f1;
1245                     QUERY PLAN                    
1246 --------------------------------------------------
1247  Nested Loop
1248    ->  Limit
1249          ->  Seq Scan on int4_tbl
1250    ->  Append
1251          ->  Index Scan using patest0i on patest0
1252                Index Cond: (id = int4_tbl.f1)
1253          ->  Index Scan using patest1i on patest1
1254                Index Cond: (id = int4_tbl.f1)
1255          ->  Seq Scan on patest2
1256                Filter: (int4_tbl.f1 = id)
1257 (10 rows)
1258
1259 select * from patest0 join (select f1 from int4_tbl limit 1) ss on id = f1;
1260  id | x | f1 
1261 ----+---+----
1262   0 | 0 |  0
1263   0 | 0 |  0
1264   0 | 0 |  0
1265 (3 rows)
1266
1267 drop table patest0 cascade;
1268 NOTICE:  drop cascades to 2 other objects
1269 DETAIL:  drop cascades to table patest1
1270 drop cascades to table patest2
1271 --
1272 -- Test merge-append plans for inheritance trees
1273 --
1274 create table matest0 (id serial primary key, name text);
1275 create table matest1 (id integer primary key) inherits (matest0);
1276 NOTICE:  merging column "id" with inherited definition
1277 create table matest2 (id integer primary key) inherits (matest0);
1278 NOTICE:  merging column "id" with inherited definition
1279 create table matest3 (id integer primary key) inherits (matest0);
1280 NOTICE:  merging column "id" with inherited definition
1281 create index matest0i on matest0 ((1-id));
1282 create index matest1i on matest1 ((1-id));
1283 -- create index matest2i on matest2 ((1-id));  -- intentionally missing
1284 create index matest3i on matest3 ((1-id));
1285 insert into matest1 (name) values ('Test 1');
1286 insert into matest1 (name) values ('Test 2');
1287 insert into matest2 (name) values ('Test 3');
1288 insert into matest2 (name) values ('Test 4');
1289 insert into matest3 (name) values ('Test 5');
1290 insert into matest3 (name) values ('Test 6');
1291 set enable_indexscan = off;  -- force use of seqscan/sort, so no merge
1292 explain (verbose, costs off) select * from matest0 order by 1-id;
1293                          QUERY PLAN                         
1294 ------------------------------------------------------------
1295  Sort
1296    Output: matest0.id, matest0.name, ((1 - matest0.id))
1297    Sort Key: ((1 - matest0.id))
1298    ->  Result
1299          Output: matest0.id, matest0.name, (1 - matest0.id)
1300          ->  Append
1301                ->  Seq Scan on public.matest0
1302                      Output: matest0.id, matest0.name
1303                ->  Seq Scan on public.matest1
1304                      Output: matest1.id, matest1.name
1305                ->  Seq Scan on public.matest2
1306                      Output: matest2.id, matest2.name
1307                ->  Seq Scan on public.matest3
1308                      Output: matest3.id, matest3.name
1309 (14 rows)
1310
1311 select * from matest0 order by 1-id;
1312  id |  name  
1313 ----+--------
1314   6 | Test 6
1315   5 | Test 5
1316   4 | Test 4
1317   3 | Test 3
1318   2 | Test 2
1319   1 | Test 1
1320 (6 rows)
1321
1322 explain (verbose, costs off) select min(1-id) from matest0;
1323                QUERY PLAN               
1324 ----------------------------------------
1325  Aggregate
1326    Output: min((1 - matest0.id))
1327    ->  Append
1328          ->  Seq Scan on public.matest0
1329                Output: matest0.id
1330          ->  Seq Scan on public.matest1
1331                Output: matest1.id
1332          ->  Seq Scan on public.matest2
1333                Output: matest2.id
1334          ->  Seq Scan on public.matest3
1335                Output: matest3.id
1336 (11 rows)
1337
1338 select min(1-id) from matest0;
1339  min 
1340 -----
1341   -5
1342 (1 row)
1343
1344 reset enable_indexscan;
1345 set enable_seqscan = off;  -- plan with fewest seqscans should be merge
1346 explain (verbose, costs off) select * from matest0 order by 1-id;
1347                             QUERY PLAN                            
1348 ------------------------------------------------------------------
1349  Merge Append
1350    Sort Key: ((1 - matest0.id))
1351    ->  Index Scan using matest0i on public.matest0
1352          Output: matest0.id, matest0.name, (1 - matest0.id)
1353    ->  Index Scan using matest1i on public.matest1
1354          Output: matest1.id, matest1.name, (1 - matest1.id)
1355    ->  Sort
1356          Output: matest2.id, matest2.name, ((1 - matest2.id))
1357          Sort Key: ((1 - matest2.id))
1358          ->  Seq Scan on public.matest2
1359                Output: matest2.id, matest2.name, (1 - matest2.id)
1360    ->  Index Scan using matest3i on public.matest3
1361          Output: matest3.id, matest3.name, (1 - matest3.id)
1362 (13 rows)
1363
1364 select * from matest0 order by 1-id;
1365  id |  name  
1366 ----+--------
1367   6 | Test 6
1368   5 | Test 5
1369   4 | Test 4
1370   3 | Test 3
1371   2 | Test 2
1372   1 | Test 1
1373 (6 rows)
1374
1375 explain (verbose, costs off) select min(1-id) from matest0;
1376                                 QUERY PLAN                                
1377 --------------------------------------------------------------------------
1378  Result
1379    Output: $0
1380    InitPlan 1 (returns $0)
1381      ->  Limit
1382            Output: ((1 - matest0.id))
1383            ->  Result
1384                  Output: ((1 - matest0.id))
1385                  ->  Merge Append
1386                        Sort Key: ((1 - matest0.id))
1387                        ->  Index Scan using matest0i on public.matest0
1388                              Output: matest0.id, (1 - matest0.id)
1389                              Index Cond: ((1 - matest0.id) IS NOT NULL)
1390                        ->  Index Scan using matest1i on public.matest1
1391                              Output: matest1.id, (1 - matest1.id)
1392                              Index Cond: ((1 - matest1.id) IS NOT NULL)
1393                        ->  Sort
1394                              Output: matest2.id, ((1 - matest2.id))
1395                              Sort Key: ((1 - matest2.id))
1396                              ->  Bitmap Heap Scan on public.matest2
1397                                    Output: matest2.id, (1 - matest2.id)
1398                                    Filter: ((1 - matest2.id) IS NOT NULL)
1399                                    ->  Bitmap Index Scan on matest2_pkey
1400                        ->  Index Scan using matest3i on public.matest3
1401                              Output: matest3.id, (1 - matest3.id)
1402                              Index Cond: ((1 - matest3.id) IS NOT NULL)
1403 (25 rows)
1404
1405 select min(1-id) from matest0;
1406  min 
1407 -----
1408   -5
1409 (1 row)
1410
1411 reset enable_seqscan;
1412 drop table matest0 cascade;
1413 NOTICE:  drop cascades to 3 other objects
1414 DETAIL:  drop cascades to table matest1
1415 drop cascades to table matest2
1416 drop cascades to table matest3
1417 --
1418 -- Check that use of an index with an extraneous column doesn't produce
1419 -- a plan with extraneous sorting
1420 --
1421 create table matest0 (a int, b int, c int, d int);
1422 create table matest1 () inherits(matest0);
1423 create index matest0i on matest0 (b, c);
1424 create index matest1i on matest1 (b, c);
1425 set enable_nestloop = off;  -- we want a plan with two MergeAppends
1426 explain (costs off)
1427 select t1.* from matest0 t1, matest0 t2
1428 where t1.b = t2.b and t2.c = t2.d
1429 order by t1.b limit 10;
1430                             QUERY PLAN                             
1431 -------------------------------------------------------------------
1432  Limit
1433    ->  Merge Join
1434          Merge Cond: (t1.b = t2.b)
1435          ->  Merge Append
1436                Sort Key: t1.b
1437                ->  Index Scan using matest0i on matest0 t1
1438                ->  Index Scan using matest1i on matest1 t1_1
1439          ->  Materialize
1440                ->  Merge Append
1441                      Sort Key: t2.b
1442                      ->  Index Scan using matest0i on matest0 t2
1443                            Filter: (c = d)
1444                      ->  Index Scan using matest1i on matest1 t2_1
1445                            Filter: (c = d)
1446 (14 rows)
1447
1448 reset enable_nestloop;
1449 drop table matest0 cascade;
1450 NOTICE:  drop cascades to table matest1
1451 --
1452 -- Test merge-append for UNION ALL append relations
1453 --
1454 set enable_seqscan = off;
1455 set enable_indexscan = on;
1456 set enable_bitmapscan = off;
1457 -- Check handling of duplicated, constant, or volatile targetlist items
1458 explain (costs off)
1459 SELECT thousand, tenthous FROM tenk1
1460 UNION ALL
1461 SELECT thousand, thousand FROM tenk1
1462 ORDER BY thousand, tenthous;
1463                                QUERY PLAN                                
1464 -------------------------------------------------------------------------
1465  Merge Append
1466    Sort Key: tenk1.thousand, tenk1.tenthous
1467    ->  Index Only Scan using tenk1_thous_tenthous on tenk1
1468    ->  Sort
1469          Sort Key: tenk1_1.thousand, tenk1_1.thousand
1470          ->  Index Only Scan using tenk1_thous_tenthous on tenk1 tenk1_1
1471 (6 rows)
1472
1473 explain (costs off)
1474 SELECT thousand, tenthous, thousand+tenthous AS x FROM tenk1
1475 UNION ALL
1476 SELECT 42, 42, hundred FROM tenk1
1477 ORDER BY thousand, tenthous;
1478                             QUERY PLAN                            
1479 ------------------------------------------------------------------
1480  Merge Append
1481    Sort Key: tenk1.thousand, tenk1.tenthous
1482    ->  Index Only Scan using tenk1_thous_tenthous on tenk1
1483    ->  Sort
1484          Sort Key: 42, 42
1485          ->  Index Only Scan using tenk1_hundred on tenk1 tenk1_1
1486 (6 rows)
1487
1488 explain (costs off)
1489 SELECT thousand, tenthous FROM tenk1
1490 UNION ALL
1491 SELECT thousand, random()::integer FROM tenk1
1492 ORDER BY thousand, tenthous;
1493                                QUERY PLAN                                
1494 -------------------------------------------------------------------------
1495  Merge Append
1496    Sort Key: tenk1.thousand, tenk1.tenthous
1497    ->  Index Only Scan using tenk1_thous_tenthous on tenk1
1498    ->  Sort
1499          Sort Key: tenk1_1.thousand, ((random())::integer)
1500          ->  Index Only Scan using tenk1_thous_tenthous on tenk1 tenk1_1
1501 (6 rows)
1502
1503 -- Check min/max aggregate optimization
1504 explain (costs off)
1505 SELECT min(x) FROM
1506   (SELECT unique1 AS x FROM tenk1 a
1507    UNION ALL
1508    SELECT unique2 AS x FROM tenk1 b) s;
1509                              QUERY PLAN                             
1510 --------------------------------------------------------------------
1511  Result
1512    InitPlan 1 (returns $0)
1513      ->  Limit
1514            ->  Merge Append
1515                  Sort Key: a.unique1
1516                  ->  Index Only Scan using tenk1_unique1 on tenk1 a
1517                        Index Cond: (unique1 IS NOT NULL)
1518                  ->  Index Only Scan using tenk1_unique2 on tenk1 b
1519                        Index Cond: (unique2 IS NOT NULL)
1520 (9 rows)
1521
1522 explain (costs off)
1523 SELECT min(y) FROM
1524   (SELECT unique1 AS x, unique1 AS y FROM tenk1 a
1525    UNION ALL
1526    SELECT unique2 AS x, unique2 AS y FROM tenk1 b) s;
1527                              QUERY PLAN                             
1528 --------------------------------------------------------------------
1529  Result
1530    InitPlan 1 (returns $0)
1531      ->  Limit
1532            ->  Merge Append
1533                  Sort Key: a.unique1
1534                  ->  Index Only Scan using tenk1_unique1 on tenk1 a
1535                        Index Cond: (unique1 IS NOT NULL)
1536                  ->  Index Only Scan using tenk1_unique2 on tenk1 b
1537                        Index Cond: (unique2 IS NOT NULL)
1538 (9 rows)
1539
1540 -- XXX planner doesn't recognize that index on unique2 is sufficiently sorted
1541 explain (costs off)
1542 SELECT x, y FROM
1543   (SELECT thousand AS x, tenthous AS y FROM tenk1 a
1544    UNION ALL
1545    SELECT unique2 AS x, unique2 AS y FROM tenk1 b) s
1546 ORDER BY x, y;
1547                          QUERY PLAN                          
1548 -------------------------------------------------------------
1549  Merge Append
1550    Sort Key: a.thousand, a.tenthous
1551    ->  Index Only Scan using tenk1_thous_tenthous on tenk1 a
1552    ->  Sort
1553          Sort Key: b.unique2, b.unique2
1554          ->  Index Only Scan using tenk1_unique2 on tenk1 b
1555 (6 rows)
1556
1557 -- exercise rescan code path via a repeatedly-evaluated subquery
1558 explain (costs off)
1559 SELECT
1560     ARRAY(SELECT f.i FROM (
1561         (SELECT d + g.i FROM generate_series(4, 30, 3) d ORDER BY 1)
1562         UNION ALL
1563         (SELECT d + g.i FROM generate_series(0, 30, 5) d ORDER BY 1)
1564     ) f(i)
1565     ORDER BY f.i LIMIT 10)
1566 FROM generate_series(1, 3) g(i);
1567                            QUERY PLAN                           
1568 ----------------------------------------------------------------
1569  Function Scan on generate_series g
1570    SubPlan 1
1571      ->  Limit
1572            ->  Merge Append
1573                  Sort Key: ((d.d + g.i))
1574                  ->  Sort
1575                        Sort Key: ((d.d + g.i))
1576                        ->  Function Scan on generate_series d
1577                  ->  Sort
1578                        Sort Key: ((d_1.d + g.i))
1579                        ->  Function Scan on generate_series d_1
1580 (11 rows)
1581
1582 SELECT
1583     ARRAY(SELECT f.i FROM (
1584         (SELECT d + g.i FROM generate_series(4, 30, 3) d ORDER BY 1)
1585         UNION ALL
1586         (SELECT d + g.i FROM generate_series(0, 30, 5) d ORDER BY 1)
1587     ) f(i)
1588     ORDER BY f.i LIMIT 10)
1589 FROM generate_series(1, 3) g(i);
1590             array             
1591 ------------------------------
1592  {1,5,6,8,11,11,14,16,17,20}
1593  {2,6,7,9,12,12,15,17,18,21}
1594  {3,7,8,10,13,13,16,18,19,22}
1595 (3 rows)
1596
1597 reset enable_seqscan;
1598 reset enable_indexscan;
1599 reset enable_bitmapscan;
1600 --
1601 -- Check that constraint exclusion works correctly with partitions using
1602 -- implicit constraints generated from the partition bound information.
1603 --
1604 create table list_parted (
1605         a       varchar
1606 ) partition by list (a);
1607 create table part_ab_cd partition of list_parted for values in ('ab', 'cd');
1608 create table part_ef_gh partition of list_parted for values in ('ef', 'gh');
1609 create table part_null_xy partition of list_parted for values in (null, 'xy');
1610 explain (costs off) select * from list_parted;
1611            QUERY PLAN           
1612 --------------------------------
1613  Append
1614    ->  Seq Scan on list_parted
1615    ->  Seq Scan on part_ab_cd
1616    ->  Seq Scan on part_ef_gh
1617    ->  Seq Scan on part_null_xy
1618 (5 rows)
1619
1620 explain (costs off) select * from list_parted where a is null;
1621            QUERY PLAN           
1622 --------------------------------
1623  Append
1624    ->  Seq Scan on list_parted
1625          Filter: (a IS NULL)
1626    ->  Seq Scan on part_null_xy
1627          Filter: (a IS NULL)
1628 (5 rows)
1629
1630 explain (costs off) select * from list_parted where a is not null;
1631            QUERY PLAN            
1632 ---------------------------------
1633  Append
1634    ->  Seq Scan on list_parted
1635          Filter: (a IS NOT NULL)
1636    ->  Seq Scan on part_ab_cd
1637          Filter: (a IS NOT NULL)
1638    ->  Seq Scan on part_ef_gh
1639          Filter: (a IS NOT NULL)
1640    ->  Seq Scan on part_null_xy
1641          Filter: (a IS NOT NULL)
1642 (9 rows)
1643
1644 explain (costs off) select * from list_parted where a in ('ab', 'cd', 'ef');
1645                         QUERY PLAN                        
1646 ----------------------------------------------------------
1647  Append
1648    ->  Seq Scan on list_parted
1649          Filter: ((a)::text = ANY ('{ab,cd,ef}'::text[]))
1650    ->  Seq Scan on part_ab_cd
1651          Filter: ((a)::text = ANY ('{ab,cd,ef}'::text[]))
1652    ->  Seq Scan on part_ef_gh
1653          Filter: ((a)::text = ANY ('{ab,cd,ef}'::text[]))
1654 (7 rows)
1655
1656 explain (costs off) select * from list_parted where a = 'ab' or a in (null, 'cd');
1657                                       QUERY PLAN                                       
1658 ---------------------------------------------------------------------------------------
1659  Append
1660    ->  Seq Scan on list_parted
1661          Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
1662    ->  Seq Scan on part_ab_cd
1663          Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
1664    ->  Seq Scan on part_ef_gh
1665          Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
1666    ->  Seq Scan on part_null_xy
1667          Filter: (((a)::text = 'ab'::text) OR ((a)::text = ANY ('{NULL,cd}'::text[])))
1668 (9 rows)
1669
1670 explain (costs off) select * from list_parted where a = 'ab';
1671                 QUERY PLAN                
1672 ------------------------------------------
1673  Append
1674    ->  Seq Scan on list_parted
1675          Filter: ((a)::text = 'ab'::text)
1676    ->  Seq Scan on part_ab_cd
1677          Filter: ((a)::text = 'ab'::text)
1678 (5 rows)
1679
1680 create table range_list_parted (
1681         a       int,
1682         b       char(2)
1683 ) partition by range (a);
1684 create table part_1_10 partition of range_list_parted for values from (1) to (10) partition by list (b);
1685 create table part_1_10_ab partition of part_1_10 for values in ('ab');
1686 create table part_1_10_cd partition of part_1_10 for values in ('cd');
1687 create table part_10_20 partition of range_list_parted for values from (10) to (20) partition by list (b);
1688 create table part_10_20_ab partition of part_10_20 for values in ('ab');
1689 create table part_10_20_cd partition of part_10_20 for values in ('cd');
1690 create table part_21_30 partition of range_list_parted for values from (21) to (30) partition by list (b);
1691 create table part_21_30_ab partition of part_21_30 for values in ('ab');
1692 create table part_21_30_cd partition of part_21_30 for values in ('cd');
1693 create table part_40_inf partition of range_list_parted for values from (40) to (unbounded) partition by list (b);
1694 create table part_40_inf_ab partition of part_40_inf for values in ('ab');
1695 create table part_40_inf_cd partition of part_40_inf for values in ('cd');
1696 create table part_40_inf_null partition of part_40_inf for values in (null);
1697 explain (costs off) select * from range_list_parted;
1698              QUERY PLAN              
1699 -------------------------------------
1700  Append
1701    ->  Seq Scan on range_list_parted
1702    ->  Seq Scan on part_1_10
1703    ->  Seq Scan on part_10_20
1704    ->  Seq Scan on part_21_30
1705    ->  Seq Scan on part_40_inf
1706    ->  Seq Scan on part_1_10_ab
1707    ->  Seq Scan on part_1_10_cd
1708    ->  Seq Scan on part_10_20_ab
1709    ->  Seq Scan on part_10_20_cd
1710    ->  Seq Scan on part_21_30_ab
1711    ->  Seq Scan on part_21_30_cd
1712    ->  Seq Scan on part_40_inf_ab
1713    ->  Seq Scan on part_40_inf_cd
1714    ->  Seq Scan on part_40_inf_null
1715 (15 rows)
1716
1717 explain (costs off) select * from range_list_parted where a = 5;
1718              QUERY PLAN              
1719 -------------------------------------
1720  Append
1721    ->  Seq Scan on range_list_parted
1722          Filter: (a = 5)
1723    ->  Seq Scan on part_1_10
1724          Filter: (a = 5)
1725    ->  Seq Scan on part_1_10_ab
1726          Filter: (a = 5)
1727    ->  Seq Scan on part_1_10_cd
1728          Filter: (a = 5)
1729 (9 rows)
1730
1731 explain (costs off) select * from range_list_parted where b = 'ab';
1732              QUERY PLAN              
1733 -------------------------------------
1734  Append
1735    ->  Seq Scan on range_list_parted
1736          Filter: (b = 'ab'::bpchar)
1737    ->  Seq Scan on part_1_10
1738          Filter: (b = 'ab'::bpchar)
1739    ->  Seq Scan on part_10_20
1740          Filter: (b = 'ab'::bpchar)
1741    ->  Seq Scan on part_21_30
1742          Filter: (b = 'ab'::bpchar)
1743    ->  Seq Scan on part_40_inf
1744          Filter: (b = 'ab'::bpchar)
1745    ->  Seq Scan on part_1_10_ab
1746          Filter: (b = 'ab'::bpchar)
1747    ->  Seq Scan on part_10_20_ab
1748          Filter: (b = 'ab'::bpchar)
1749    ->  Seq Scan on part_21_30_ab
1750          Filter: (b = 'ab'::bpchar)
1751    ->  Seq Scan on part_40_inf_ab
1752          Filter: (b = 'ab'::bpchar)
1753 (19 rows)
1754
1755 explain (costs off) select * from range_list_parted where a between 3 and 23 and b in ('ab');
1756                            QUERY PLAN                            
1757 -----------------------------------------------------------------
1758  Append
1759    ->  Seq Scan on range_list_parted
1760          Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
1761    ->  Seq Scan on part_1_10
1762          Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
1763    ->  Seq Scan on part_10_20
1764          Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
1765    ->  Seq Scan on part_21_30
1766          Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
1767    ->  Seq Scan on part_1_10_ab
1768          Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
1769    ->  Seq Scan on part_10_20_ab
1770          Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
1771    ->  Seq Scan on part_21_30_ab
1772          Filter: ((a >= 3) AND (a <= 23) AND (b = 'ab'::bpchar))
1773 (15 rows)
1774
1775 /* Should select no rows because range partition key cannot be null */
1776 explain (costs off) select * from range_list_parted where a is null;
1777         QUERY PLAN        
1778 --------------------------
1779  Result
1780    One-Time Filter: false
1781 (2 rows)
1782
1783 /* Should only select rows from the null-accepting partition */
1784 explain (costs off) select * from range_list_parted where b is null;
1785              QUERY PLAN              
1786 -------------------------------------
1787  Append
1788    ->  Seq Scan on range_list_parted
1789          Filter: (b IS NULL)
1790    ->  Seq Scan on part_1_10
1791          Filter: (b IS NULL)
1792    ->  Seq Scan on part_10_20
1793          Filter: (b IS NULL)
1794    ->  Seq Scan on part_21_30
1795          Filter: (b IS NULL)
1796    ->  Seq Scan on part_40_inf
1797          Filter: (b IS NULL)
1798    ->  Seq Scan on part_40_inf_null
1799          Filter: (b IS NULL)
1800 (13 rows)
1801
1802 explain (costs off) select * from range_list_parted where a is not null and a < 67;
1803                    QUERY PLAN                   
1804 ------------------------------------------------
1805  Append
1806    ->  Seq Scan on range_list_parted
1807          Filter: ((a IS NOT NULL) AND (a < 67))
1808    ->  Seq Scan on part_1_10
1809          Filter: ((a IS NOT NULL) AND (a < 67))
1810    ->  Seq Scan on part_10_20
1811          Filter: ((a IS NOT NULL) AND (a < 67))
1812    ->  Seq Scan on part_21_30
1813          Filter: ((a IS NOT NULL) AND (a < 67))
1814    ->  Seq Scan on part_40_inf
1815          Filter: ((a IS NOT NULL) AND (a < 67))
1816    ->  Seq Scan on part_1_10_ab
1817          Filter: ((a IS NOT NULL) AND (a < 67))
1818    ->  Seq Scan on part_1_10_cd
1819          Filter: ((a IS NOT NULL) AND (a < 67))
1820    ->  Seq Scan on part_10_20_ab
1821          Filter: ((a IS NOT NULL) AND (a < 67))
1822    ->  Seq Scan on part_10_20_cd
1823          Filter: ((a IS NOT NULL) AND (a < 67))
1824    ->  Seq Scan on part_21_30_ab
1825          Filter: ((a IS NOT NULL) AND (a < 67))
1826    ->  Seq Scan on part_21_30_cd
1827          Filter: ((a IS NOT NULL) AND (a < 67))
1828    ->  Seq Scan on part_40_inf_ab
1829          Filter: ((a IS NOT NULL) AND (a < 67))
1830    ->  Seq Scan on part_40_inf_cd
1831          Filter: ((a IS NOT NULL) AND (a < 67))
1832    ->  Seq Scan on part_40_inf_null
1833          Filter: ((a IS NOT NULL) AND (a < 67))
1834 (29 rows)
1835
1836 explain (costs off) select * from range_list_parted where a >= 30;
1837              QUERY PLAN              
1838 -------------------------------------
1839  Append
1840    ->  Seq Scan on range_list_parted
1841          Filter: (a >= 30)
1842    ->  Seq Scan on part_40_inf
1843          Filter: (a >= 30)
1844    ->  Seq Scan on part_40_inf_ab
1845          Filter: (a >= 30)
1846    ->  Seq Scan on part_40_inf_cd
1847          Filter: (a >= 30)
1848    ->  Seq Scan on part_40_inf_null
1849          Filter: (a >= 30)
1850 (11 rows)
1851
1852 drop table list_parted;
1853 drop table range_list_parted;