In PostgreSQL, non v'è alcun tipo di ereditarietà diretta, ma avete alcune opzioni:
1. Table inheritance
È possibile creare ereditate tabelle per creare tipi ereditati (PostgreSQL sarà sempre creare un tipo composito per ogni tavolo, con lo stesso nome):
create table supertable (
foo int,
bar text
);
create table subtable (
baz int
) inherits (supertable);
2. Construct views using each other
Perché viste sono (in realtà) tabelle (con rules), viene creato un tipo per ciascuna di esse anche:
create view superview
as select null::int foo,
null::text bar;
create view subview
as select superview.*,
null::int baz
from superview;
3. Type composition
Questo è quello, hai provato. Lei ha più controllo con questo in generale:
create type supertype as (
foo int,
bar text
);
create type subtype as (
super supertype,
baz int
);
-- resolve composition manually
select get_foo(v), -- this will call get_foo(subtype)
get_foo((v).super) -- this will call get_foo(supertype)
from (values (((1, '2'), 3)::subtype)) v(v);
+1 Vero tipo di ereditarietà?
PostgreSQL's documentation explicitly says, che l'ereditarietà tabella non è il tipo di ereditarietà dello standard:
SQL: 1999 e successivamente definire una caratteristica di ereditarietà tipo, che differisce in molti aspetti delle caratteristiche descritte qui.
Tuttavia, ereditato i tipi di auto-creato della tabella funzionano davvero come veri tipi ereditati (possono essere utilizzati, in cui il tipo di super-può essere utilizzato):
-- 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