As a note, the following also works:

CREATE TYPE foo AS (bar text, baz int);
CREATE TABLE table_of_foo OF foo (primary key(bar));

The one thing that doesn't work is the REF syntax and the operators that go
along with that.  However, you could come up with dereferencing functions
and operators oneself.

Personally in this case I would probably use inheritance instead for the
simple reason that tables can inherit but complex types cannot.  You can
use CHECK(false) NOINHERIT to effectively relegate a table to a type if you
have a sufficiently recent version of PostgreSQL.

Best Wishes,
Chris Travers

Reply via email to