--
-- Test inheritance features
--
CREATE TABLE a (aa TEXT);
CREATE TABLE b UNDER a (bb TEXT);
CREATE TABLE c UNDER a (cc TEXT);
CREATE TABLE d UNDER b,c,a (dd TEXT);
INSERT INTO a(aa) VALUES('aaa');
INSERT INTO a(aa) VALUES('aaaa');
INSERT INTO a(aa) VALUES('aaaaa');
INSERT INTO a(aa) VALUES('aaaaaa');
INSERT INTO a(aa) VALUES('aaaaaaa');
INSERT INTO a(aa) VALUES('aaaaaaaa');
INSERT INTO b(aa) VALUES('bbb');
INSERT INTO b(aa) VALUES('bbbb');
INSERT INTO b(aa) VALUES('bbbbb');
INSERT INTO b(aa) VALUES('bbbbbb');
INSERT INTO b(aa) VALUES('bbbbbbb');
INSERT INTO b(aa) VALUES('bbbbbbbb');
INSERT INTO c(aa) VALUES('ccc');
INSERT INTO c(aa) VALUES('cccc');
INSERT INTO c(aa) VALUES('ccccc');
INSERT INTO c(aa) VALUES('cccccc');
INSERT INTO c(aa) VALUES('ccccccc');
INSERT INTO c(aa) VALUES('cccccccc');
INSERT INTO d(aa) VALUES('ddd');
INSERT INTO d(aa) VALUES('dddd');
INSERT INTO d(aa) VALUES('ddddd');
INSERT INTO d(aa) VALUES('dddddd');
INSERT INTO d(aa) VALUES('ddddddd');
INSERT INTO d(aa) VALUES('dddddddd');
SELECT * FROM a;
    aa    
----------
 aaa
 aaaa
 aaaaa
 aaaaaa
 aaaaaaa
 aaaaaaaa
 bbb
 bbbb
 bbbbb
 bbbbbb
 bbbbbbb
 bbbbbbbb
 ccc
 cccc
 ccccc
 cccccc
 ccccccc
 cccccccc
 ddd
 dddd
 ddddd
 dddddd
 ddddddd
 dddddddd
(24 rows)

SELECT * FROM b;
    aa    | bb 
----------+----
 bbb      | 
 bbbb     | 
 bbbbb    | 
 bbbbbb   | 
 bbbbbbb  | 
 bbbbbbbb | 
 ddd      | 
 dddd     | 
 ddddd    | 
 dddddd   | 
 ddddddd  | 
 dddddddd | 
(12 rows)

SELECT * FROM c;
    aa    | cc 
----------+----
 ccc      | 
 cccc     | 
 ccccc    | 
 cccccc   | 
 ccccccc  | 
 cccccccc | 
 ddd      | 
 dddd     | 
 ddddd    | 
 dddddd   | 
 ddddddd  | 
 dddddddd | 
(12 rows)

SELECT * FROM d;
    aa    | bb | cc | dd 
----------+----+----+----
 ddd      |    |    | 
 dddd     |    |    | 
 ddddd    |    |    | 
 dddddd   |    |    | 
 ddddddd  |    |    | 
 dddddddd |    |    | 
(6 rows)

SELECT * FROM ONLY a;
    aa    
----------
 aaa
 aaaa
 aaaaa
 aaaaaa
 aaaaaaa
 aaaaaaaa
(6 rows)

SELECT * FROM ONLY b;
    aa    | bb 
----------+----
 bbb      | 
 bbbb     | 
 bbbbb    | 
 bbbbbb   | 
 bbbbbbb  | 
 bbbbbbbb | 
(6 rows)

SELECT * FROM ONLY c;
    aa    | cc 
----------+----
 ccc      | 
 cccc     | 
 ccccc    | 
 cccccc   | 
 ccccccc  | 
 cccccccc | 
(6 rows)

SELECT * FROM ONLY d;
    aa    | bb | cc | dd 
----------+----+----+----
 ddd      |    |    | 
 dddd     |    |    | 
 ddddd    |    |    | 
 dddddd   |    |    | 
 ddddddd  |    |    | 
 dddddddd |    |    | 
(6 rows)

UPDATE a SET aa='zzzz' WHERE aa='aaaa';
UPDATE ONLY a SET aa='zzzzz' WHERE aa='aaaaa';
UPDATE b SET aa='zzz' WHERE aa='aaa';
UPDATE ONLY b SET aa='zzz' WHERE aa='aaa';
UPDATE a SET aa='zzzzzz' WHERE aa LIKE 'aaa%';
SELECT * FROM a;
    aa    
----------
 zzzz
 zzzzz
 zzzzzz
 zzzzzz
 zzzzzz
 zzzzzz
 bbb
 bbbb
 bbbbb
 bbbbbb
 bbbbbbb
 bbbbbbbb
 ccc
 cccc
 ccccc
 cccccc
 ccccccc
 cccccccc
 ddd
 dddd
 ddddd
 dddddd
 ddddddd
 dddddddd
(24 rows)

SELECT * FROM b;
    aa    | bb 
----------+----
 bbb      | 
 bbbb     | 
 bbbbb    | 
 bbbbbb   | 
 bbbbbbb  | 
 bbbbbbbb | 
 ddd      | 
 dddd     | 
 ddddd    | 
 dddddd   | 
 ddddddd  | 
 dddddddd | 
(12 rows)

SELECT * FROM c;
    aa    | cc 
----------+----
 ccc      | 
 cccc     | 
 ccccc    | 
 cccccc   | 
 ccccccc  | 
 cccccccc | 
 ddd      | 
 dddd     | 
 ddddd    | 
 dddddd   | 
 ddddddd  | 
 dddddddd | 
(12 rows)

SELECT * FROM d;
    aa    | bb | cc | dd 
----------+----+----+----
 ddd      |    |    | 
 dddd     |    |    | 
 ddddd    |    |    | 
 dddddd   |    |    | 
 ddddddd  |    |    | 
 dddddddd |    |    | 
(6 rows)

SELECT * FROM ONLY a;
   aa   
--------
 zzzz
 zzzzz
 zzzzzz
 zzzzzz
 zzzzzz
 zzzzzz
(6 rows)

SELECT * FROM ONLY b;
    aa    | bb 
----------+----
 bbb      | 
 bbbb     | 
 bbbbb    | 
 bbbbbb   | 
 bbbbbbb  | 
 bbbbbbbb | 
(6 rows)

SELECT * FROM ONLY c;
    aa    | cc 
----------+----
 ccc      | 
 cccc     | 
 ccccc    | 
 cccccc   | 
 ccccccc  | 
 cccccccc | 
(6 rows)

SELECT * FROM ONLY d;
    aa    | bb | cc | dd 
----------+----+----+----
 ddd      |    |    | 
 dddd     |    |    | 
 ddddd    |    |    | 
 dddddd   |    |    | 
 ddddddd  |    |    | 
 dddddddd |    |    | 
(6 rows)

UPDATE b SET aa='new';
SELECT * FROM a;
    aa    
----------
 zzzz
 zzzzz
 zzzzzz
 zzzzzz
 zzzzzz
 zzzzzz
 new
 new
 new
 new
 new
 new
 ccc
 cccc
 ccccc
 cccccc
 ccccccc
 cccccccc
 new
 new
 new
 new
 new
 new
(24 rows)

SELECT * FROM b;
 aa  | bb 
-----+----
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
(12 rows)

SELECT * FROM c;
    aa    | cc 
----------+----
 ccc      | 
 cccc     | 
 ccccc    | 
 cccccc   | 
 ccccccc  | 
 cccccccc | 
 new      | 
 new      | 
 new      | 
 new      | 
 new      | 
 new      | 
(12 rows)

SELECT * FROM d;
 aa  | bb | cc | dd 
-----+----+----+----
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
(6 rows)

SELECT * FROM ONLY a;
   aa   
--------
 zzzz
 zzzzz
 zzzzzz
 zzzzzz
 zzzzzz
 zzzzzz
(6 rows)

SELECT * FROM ONLY b;
 aa  | bb 
-----+----
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
(6 rows)

SELECT * FROM ONLY c;
    aa    | cc 
----------+----
 ccc      | 
 cccc     | 
 ccccc    | 
 cccccc   | 
 ccccccc  | 
 cccccccc | 
(6 rows)

SELECT * FROM ONLY d;
 aa  | bb | cc | dd 
-----+----+----+----
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
(6 rows)

UPDATE a SET aa='new';
DELETE FROM ONLY c WHERE aa='new';
SELECT * FROM a;
 aa  
-----
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
 new
(18 rows)

SELECT * FROM b;
 aa  | bb 
-----+----
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
(12 rows)

SELECT * FROM c;
 aa  | cc 
-----+----
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
(6 rows)

SELECT * FROM d;
 aa  | bb | cc | dd 
-----+----+----+----
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
(6 rows)

SELECT * FROM ONLY a;
 aa  
-----
 new
 new
 new
 new
 new
 new
(6 rows)

SELECT * FROM ONLY b;
 aa  | bb 
-----+----
 new | 
 new | 
 new | 
 new | 
 new | 
 new | 
(6 rows)

SELECT * FROM ONLY c;
 aa | cc 
----+----
(0 rows)

SELECT * FROM ONLY d;
 aa  | bb | cc | dd 
-----+----+----+----
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
 new |    |    | 
(6 rows)

DELETE FROM a;
SELECT * FROM a;
 aa 
----
(0 rows)

SELECT * FROM b;
 aa | bb 
----+----
(0 rows)

SELECT * FROM c;
 aa | cc 
----+----
(0 rows)

SELECT * FROM d;
 aa | bb | cc | dd 
----+----+----+----
(0 rows)

SELECT * FROM ONLY a;
 aa 
----
(0 rows)

SELECT * FROM ONLY b;
 aa | bb 
----+----
(0 rows)

SELECT * FROM ONLY c;
 aa | cc 
----+----
(0 rows)

SELECT * FROM ONLY d;
 aa | bb | cc | dd 
----+----+----+----
(0 rows)

