PostgreSQL provides two methods for implementing user-defined data types through the following commands:
CREATE DOMAIN
: TheCREATE DOMAIN
command allows developers to create a user-defined data type with constraints. This helps to make the source code more modular.CREATE TYPE
: TheCREATE TYPE
command is often used to create a composite type, which is useful in procedural languages, and is used as the return data type. Also, one can use the create type to create theENUM
type, which is useful to decrease the number of joins, specifically for lookup tables.
Often, developers tend not to use user-defined data types and use flat tables instead due to a lack of support on the driver side, such as JDBC and ODBC. Nonetheless, in JDBC, the composite data types can be retried as Java objects and parsed manually.
Domain objects, as with other database objects, should have a unique name within the schema scope. The first use case of domains is to use them for common patterns. For...