Let's create two simple tables:
CREATE TABLE users (username text, email text);
CREATE TABLE simple_users () INHERITS (users);
ALTER TABLE simple_users ADD COLUMN password text;
Column | Type |
---|---|
username | text |
text | |
password | text |
Adding the same column to the parent table will merge the definition of both columns:
ALTER TABLE users ADD COLUMN password text;
NOTICE: merging definition of column "password" for child "simple_users"
Using our altered tables:
ALTER TABLE users DROP COLUMN password;
Column | Type |
---|---|
username | text |
text |
Column | Type |
---|---|
username | text |
text | |
password | text |
Since we first added the column to simple_users
, PostgreSQL makes sure this column isn't dropped.
Now if we had another child table, its password
column would, of course, have been dropped.