FirebirdSQL logo
 SQL Language StructureCommon Language Elements 

Custom Data Types — Domains

In Firebird, the concept of a “user-defined data type” is implemented in the form of the domain.Creating a domain does not truly create a new data type, of course.A domain provides the means to encapsulate an existing data type with a set of attributes and make this “capsule” available for reuse across the whole database.If several tables need columns defined with identical or nearly identical attributes, a domain makes sense.

Domain usage is not limited to column definitions for tables and views.Domains can be used to declare input and output parameters and variables in PSQL code.

Domain Attributes

A domain definition has required and optional attributes.The data type is a required attribute.Optional attributes include:

  • a default value

  • to allow or forbid NULL

  • CHECK constraints

  • character set (for character data types and text BLOB fields)

  • collation (for character data types)

Sample domain definition
CREATE DOMAIN BOOL3 AS SMALLINT
  CHECK (VALUE IS NULL OR VALUE IN (0, 1));
See also

Explicit Data Type Conversion for the description of differences in the data conversion mechanism when domains are specified for the TYPE OF and TYPE OF COLUMN modifiers.