There is no direct type inheritance in PostgreSQL, but you have several options:
1. Inheritance of tables
You can create inherited tables to create inherited types (PostgreSQL will always create a composite type for each table with the same name):
create table supertable ( foo int, bar text ); create table subtable ( baz int ) inherits (supertable);
2. Build views with each other
Since views are (in fact) tables (with rules ), a type is created for each of them:
create view superview as select null::int foo, null::text bar; create view subview as select superview.*, null::int baz from superview;
3. Type of composition
This is what you have tried. You have more control with this overall:
create type supertype as ( foo int, bar text ); create type subtype as ( super supertype, baz int );
+1 Inheritance True type?
The PostgreSQL documentation explicitly says that table inheritance is not standard type inheritance:
SQL: 1999 and later define a type inheritance function that is very different from the functions described here.
However, inherited automatically generated table types do work as true inherited types (you can use them where you can use a super type):
-- if there is a get_foo(supertable) function, -- but there is no get_foo(subtable) function: select get_foo((1, '2')::supertable); -- will call get_foo(supertable) select get_foo((1, '2', 3)::subtable); -- will also call get_foo(supertable)
SQLFiddle