Skip to main content
Version: 2.0.0 (latest)

3.15. Domains

Domains behave as data types with optional built-in constraints. The main advantage of using domains is to have in one place a data type with a specific validation instead of creating separate columns in tables and applying to them the needed constraints to provide correctness when assigning values.

One simple example is an email column in different tables: the data type, semantics, and validation for this column are the same; thus, a neat approach is to create a domain called email with the needed constraints and assign it as the data type of the columns that require it. This is the principle of object reuse: no redundancy and no repeated creation of the same object with the same purpose. Additionally, you have only one object to make the changes when needed.

ch3.domain-dialog.general1234567

General
#FieldGroup boxDescription
1TypeData type

The data type. Besides the built-in types, the list also holds the user-defined types, domains and other types of the model.

2LengthData type

Length, or number of characters or bits, for the types that accept one, like varchar(n) or bit(n). Disabled for the other types.

3PrecisionData type

Precision, for the types that accept it, like numeric(p, s), or the number of fractional digits of seconds for time and timestamp. Disabled for the other types.

4DimensionData type

Number of dimensions when the type is an array (type[]). 0 means that the type is not an array.

5FormatData type

Read-only preview of the data type as it is written in the SQL code, with length, precision, dimension and other modifiers applied.

6Default Value

The default value of the domain. It must be written in the format accepted by the domain's data type.

7Not null

Indicates whether the domain accepts null values. When checked, null values are rejected (NOT NULL).

ch3.domain-dialog.check-constraints123

Check constraints
#FieldDescription
1Name

The name of the check constraint being added to the domain.

2Expression

The SQL expression of the check constraint, used to validate any value assigned to the domain.

3Check constraints

The check constraints of the domain. Type the name and the expression in the fields above and use the add button to include a constraint.

References​

Domain DDL
https://www.postgresql.org/docs/current/static/sql-createdomain.html