A new table created with inherits inherits one or more parent tables, the child table inherits only the table structure of the parent table and the not null,default,check three constraints, the primary key, the foreign key and the unique key, and the index are not inherited, so modify the structure of the parent table (additions and deletions), not NULL, Default and check constraints are automatically modified with the schedule.
Example 1.
Create TableTbl_inherits_parent (Aint not NULL, bvarchar( +) not NULL default 'Got u', Cint Check(c> 0), D date not NULL); test=#Alter TableTbl_inherits_parentAdd constraintPk_tbl_inherits_parent_aPrimary Key(a);ALTER TABLETest=#Alter TableTbl_inherits_parentAdd constraintUk_tbl_inherits_parent_b_dUnique(b,d);ALTER TABLETest=#Create TableTbl_inherits_partition () inherits (Tbl_inherits_parent);CREATE TABLETest=# \d Tbl_inherits_partitionTable" Public. Tbl_inherits_partition "Column |Type|Modifiers--------+-----------------------+---------------------------------------------A| integer | not NULLb| character varying( +)| not NULL default 'Got u'::character varyingC| integer |D|Date| not NULLCheckconstraints: "Tbl_inherits_parent_c_check"CHECK(c> 0)inherits:tbl_inherits_parent
Example 2.
Test=#Alter TableTbl_inherits_parentAdd columnEint not NULL default 0;ALTER TABLETest=#Alter TableTbl_inherits_parentAlter columnBSet default 'Try Me';ALTER TABLETest=# \d Tbl_inherits_partitionTable" Public. Tbl_inherits_partition "Column |Type|Modifiers--------+-----------------------+----------------------------------------------A| integer | not NULLb| character varying( +)| not NULL default 'Try Me'::character varyingC| integer |D|Date| not NULLe| integer | not NULL default 0Checkconstraints: "Tbl_inherits_parent_c_check"CHECK(c> 0)inherits:tbl_inherits_parent
Example 3.
In addition to inheriting the parent table, you can add your own fields when creating child tables
Test=#Create TableTbl_inherits_partition1 (fint) inherits (Tbl_inherits_parent);CREATE TABLETest=# \d Tbl_inherits_partition1Table" Public. Tbl_inherits_partition1 "Column |Type|Modifiers--------+-----------------------+----------------------------------------------A| integer | not NULLb| character varying( +)| not NULL default 'Try Me'::character varyingC| integer |D|Date| not NULLe| integer | not NULL default 0F| integer | Checkconstraints: "Tbl_inherits_parent_c_check"CHECK(c> 0)inherits:tbl_inherits_parent
Example 4. de-Inheritance
Test=#Alter TableTbl_inherits_partition1 no inherit tbl_inherits_parent;ALTER TABLETest=# \d Tbl_inherits_partition1Table" Public. Tbl_inherits_partition1 "Column |Type|Modifiers--------+-----------------------+----------------------------------------------A| integer | not NULLb| character varying( +)| not NULL default 'Try Me'::character varyingC| integer |D|Date| not NULLe| integer | not NULL default 0F| integer | Checkconstraints: "Tbl_inherits_parent_c_check"CHECK(c> 0)
PostgreSQL----Inherit tables Inherits parent table