Ely Fialkoff
Ely Fialkoff

Reputation: 652

I want one table to inherit from another

I have 2 SQL tables say all_cities, regular_cities, (and capitol_cities).

all_cities has 2 columns : name, population regular_cities has 2 columns : name, population capitol_cities has 3 columns : name, population, state

These tables are already created. I want to connect them using table partitioning but first I need to make sure that tables regular_cities and capitol_cities inherit from all_cities.

Is there anyway to have these tables inherit from another table even after the tables are created or only when creating a new table?

Upvotes: 1

Views: 673

Answers (1)

Ely Fialkoff
Ely Fialkoff

Reputation: 652

After searching around the correct way to do this is with a simple ALTER statement ALTER TABLE <child_table> INHERIT <parent_table>; That's it!

Documentation here https://www.postgresql.org/docs/9.6/static/sql-altertable.html

Upvotes: 1

Related Questions