Extending Types

PostgreSQL has a plethora of built-in data types (see Chapter 2, “PostgreSQL Data Types”). However, in specific cases, it might be advantageous to create custom-defined data types.

All the data types in PostgreSQL can be defined as belonging to one of the following cases: base types or composites.

Base types, like int4, are written in C and are compiled into the system. However, custom data types can be compiled as shared objects and linked to the back end by using the CREATE TYPE command.

Composite types are created whenever a new table is created. At first it might seem counterintuitive to think of a table as a type. However, tables are merely collections of single data types grouped in a specific order. In that way, a table ...

Get PostgreSQL Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.