Type-specific Details
- Array Types
-
-
If the domain is to be an array, the base type can be any SQL data type except
BLOBand array. -
The dimensions of the array are specified between square brackets.
-
For each array dimension, one or two integer numbers define the lower and upper boundaries of its index range:
-
By default, arrays are 1-based.The lower boundary is implicit and only the upper boundary need be specified.A single number smaller than 1 defines the range num..1 and a number greater than 1 defines the range 1..num.
-
Two numbers separated by a colon (‘
:’) and optional whitespace, the second greater than the first, can be used to define the range explicitly.One or both boundaries can be less than zero, as long as the upper boundary is greater than the lower.
-
-
When the array has multiple dimensions, the range definitions for each dimension must be separated by commas and optional whitespace.
-
Subscripts are validated only if an array actually exists.It means that no error messages regarding invalid subscripts will be returned if selecting a specific element returns nothing or if an array field is
NULL.
-
- String Types
-
You can use the
CHARACTER SETclause to specify the character set for theCHAR,VARCHARandBLOB(SUB_TYPE TEXT) types.If the character set is not specified, the character set specified asDEFAULT CHARACTER SETof the database will be used.If the database has no default character set, the character setNONEis applied by default when you create a character domain.WarningWith character set
NONE, character data are stored and retrieved the way they were submitted.Data in any encoding can be added to a column based on such a domain, but it is impossible to add this data to a column with a different encoding.Because no transliteration is performed between the source and destination encodings, errors may result. DEFAULTClause-
The optional
DEFAULTclause allows you to specify a default value for the domain.This value will be added to the table column that inherits this domain when theINSERTstatement is executed, if no value is specified for it in the DML statement.Local variables and arguments in PSQL modules that reference this domain will be initialized with the default value.For the default value, use a literal of a compatible type or a context variable of a compatible type. NOT NULLConstraint-
Columns and variables based on a domain with the
NOT NULLconstraint will be prevented from being written asNULL, i.e. a value is required.CautionWhen creating a domain, take care to avoid specifying limitations that would contradict one another.For instance,
NOT NULLandDEFAULT NULLare contradictory. CHECKConstraint(s)-
The optional
CHECKclause specifies constraints for the domain.A domain constraint specifies conditions that must be satisfied by the values of table columns or variables that inherit from the domain.A condition must be enclosed in parentheses.A condition is a logical expression (also called a predicate) that can return the Boolean resultsTRUE,FALSEandUNKNOWN.A condition is considered satisfied if the predicate returns the valueTRUEor “unknown value” (equivalent toNULL).If the predicate returnsFALSE, the condition for acceptance is not met. VALUEKeyword-
The keyword
VALUEin a domain constraint substitutes for the table column that is based on this domain or for a variable in a PSQL module.It contains the value assigned to the variable or the table column.VALUEcan be used anywhere in theCHECKconstraint, though it is usually used in the left part of the condition. COLLATE-
The optional
COLLATEclause allows you to specify the collation if the domain is based on one of the string data types, includingBLOBs with text subtypes.If no collation is specified, the collation will be the one that is default for the specified character set at the time the domain is created.