CREATE TABLE base (id INT, value1 VARCHAR(256));
CREATE TABLE base_1 (CHECK (id = 1)) INHERITS (base);
CREATE RULE base_insert_1 AS ON INSERT TO base WHERE (id = 1) DO INSTEAD INSERT INTO base_1 VALUES (NEW.id, NEW.value1);
CREATE TABLE base_2 (CHECK (id = 2)) INHERITS (base);
CREATE RULE base_insert_2 AS ON INSERT TO base WHERE (id = 2) DO INSTEAD INSERT INTO base_2 VALUES (NEW.id, NEW.value1);
CREATE TABLE base_3 (CHECK (id = 3)) INHERITS (base);
CREATE RULE base_insert_3 AS ON INSERT TO base WHERE (id = 3) DO INSTEAD INSERT INTO base_3 VALUES (NEW.id, NEW.value1);

CREATE TABLE another (id INT, value2 VARCHAR(256));
CREATE TABLE another_1 (CHECK (id = 1)) INHERITS (another);
CREATE RULE another_insert_1 AS ON INSERT TO another WHERE (id = 1) DO INSTEAD INSERT INTO another_1 VALUES (NEW.id, NEW.value2);
CREATE TABLE another_2 (CHECK (id = 2)) INHERITS (another);
CREATE RULE another_insert_2 AS ON INSERT TO another WHERE (id = 2) DO INSTEAD INSERT INTO another_2 VALUES (NEW.id, NEW.value2);
CREATE TABLE another_3 (CHECK (id = 3)) INHERITS (another);
CREATE RULE another_insert_3 AS ON INSERT TO another WHERE (id = 3) DO INSTEAD INSERT INTO another_3 VALUES (NEW.id, NEW.value2);

CREATE TABLE ba (id INT, value1 VARCHAR(256), value2 VARCHAR(256));
CREATE TABLE ba_1 (CHECK (id = 1)) INHERITS (ba);
CREATE RULE ba_insert_1 AS ON INSERT TO ba WHERE (id = 1) DO INSTEAD INSERT INTO ba_1 VALUES (NEW.id, NEW.value1, NEW.value2);
CREATE TABLE ba_2 (CHECK (id = 2)) INHERITS (ba);
CREATE RULE ba_insert_2 AS ON INSERT TO ba WHERE (id = 2) DO INSTEAD INSERT INTO ba_2 VALUES (NEW.id, NEW.value1, NEW.value2);
CREATE TABLE ba_3 (CHECK (id = 3)) INHERITS (ba);
CREATE RULE ba_insert_3 AS ON INSERT TO ba WHERE (id = 3) DO INSTEAD INSERT INTO ba_3 VALUES (NEW.id, NEW.value1, NEW.value2);

CREATE VIEW ba_view AS
 SELECT base.id, base.value1, another.value2
   FROM base JOIN another USING (ID);

INSERT INTO base VALUES (1, 'value1');
INSERT INTO another VALUES (1, 'value2');
