PostgreSQL provides two methods to implement user-defined data types, via the following commands:
- CREATE DOMAIN: The CREATE DOMAIN command allows developers to create a user-defined data type with constraints. This helps to make the source code more modular.
- CREATE TYPE: The CREATE 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, we can use the CREATE TYPE to create the ENUM type, which is useful to decrease the number of joins, specifically for lookup tables.
Often, developers decide not to use user-defined data types and to use flat tables instead, due to a lack of support on the driver side, such as JDBC and ODBC. Nonetheless, ...