User-defined type systems
PostgreSQL allows users to define their own data-types, which can be used in the same way as the in-built datatypes. A user-defined data-type can be a base type, a composite WySH, D GRPDLQ Rr DQ HQXPHrDWLRQ. UVHr-GHILQHG types can be defined by using the CREATE TYPE ( base, composite and enumeration) or CREATE DOMAIN (domain) commands.
Composite types are a collection of other data-types with DVVRFLDWHG fiHOG QDPHV, OLNH VWrXFWXrHV LQ C. ThH PHPEHrV RI a composite type can be accessed in SQL queries, functions, HWF. $Q HxDPSOH GHfiQLQJ D FRPSRVLWH WySH ‘complex’ can be found in this article.
Domain types, on the other hand, can be created by constraining the base types. Although the constraints restrict the valid values of a domain type to a subset of values allowed by the underlying base type, for many purposes, a base type and the types based on it are interchangeable.
Base types are usually implemented in a low-level language like C, which is below the level of the SQL language. The behaviour of such a data-type needs to be GHfiQHG Ey WhH XVHr LQ WHrPV RI LQSXW/RXWSXW IXQFWLRQV (XVXDOOy inverses of each other), which decide how the data-type appears in string form for input/output by the user. The same functions will decide how the type is organised in memory. The implementation can be provided through shared libraries.