0

Is it possible to have single row in a parent table be visible in more than one inherited (child) table?

Perhaps by inserting a row directly into the master table and then "making it visible" in one or more than one inherited table?

To clarify:

I want to insert into the parent table, then make that row visible in one or more child tables. If the row is updated in one child table, the changes are immediately present in all tables where it is visible.

It does seem like this is not how Postgres inherited tables work, they appear to be more of a partitioning scheme.

I was thinking if I have a generic table with person information, then I could have a child table with that "person" and additional attributes, but if that person also belonged to a different class I could "make it visible" in another child table which would add different attributes. If however I changed the person's contact number, which is generic and comes from the parent table, then that would be reflected in all the child tables where this row is seen.

1 Answer 1

0

I'm not sure exactly what you're asking. The table which inherits has all of its rows show when you query the parent.

CREATE TEMP TABLE foo ( id int );
CREATE TEMP TABLE bar () INHERITS (foo);
INSERT INTO foo VALUES (1);
INSERT INTO bar VALUES (1);

test=# TABLE bar;
 id 
----
  1
(1 row)

test=# TABLE foo;
 id 
----
  1
  1
(2 rows)
1
  • I think he might be after several children and possibly in multiple levels. I stole your example and extended it at: dbfiddle.uk/… Commented Apr 9, 2020 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.