3.12 Data Type Declaration Syntax

This section documents the syntax of declaring data types. Data type declaration commonly occurs in DDL statements, but also in CAST and EXECUTE BLOCK.

The syntax documented below is referenced from other parts of this language reference.

3.12.1 Scalar Data Types Syntax

The scalar data types are simple data types that hold a single value. For reasons of organisation, the syntax of BLOB types are defined separately in Section 3.12.2, BLOB Data Types Syntax.

Scalar Data Types Syntax

  1. <domain_or_non_array_type> ::=
  2. <scalar_datatype>
  3. | <blob_datatype>
  4. | [TYPE OF] domain
  5. | TYPE OF COLUMN rel.col
  6. <scalar_datatype> ::=
  7. SMALLINT | INT[EGER] | BIGINT | INT128
  8. | REAL | FLOAT [(bin_prec)] | DOUBLE PRECISION
  9. | DECFLOAT [(dec_prec)]
  10. | BOOLEAN
  11. | DATE | TIME | TIMESTAMP
  12. | {DECIMAL | NUMERIC} [(precision [, scale])]
  13. | {VARCHAR | {CHAR | CHARACTER} VARYING} (length)
  14. [CHARACTER SET charset]
  15. | {CHAR | CHARACTER} [(length)] [CHARACTER SET charset]
  16. | {NCHAR | NATIONAL {CHARACTER | CHAR}} VARYING (length)
  17. | {NCHAR | NATIONAL {CHARACTER | CHAR}} [(length)]
  18. | BINARY [(length)]
  19. | {VARBINARY | BINARY VARYING} (length)

Table 3.12.1.1 Arguments for the Scalar Data Types Syntax

ArgumentDescription

domain

Domain (only non-array domains)

rel

Name of a table or view

col

Name of a column in a table or view (only columns of a non-array type)

bin_prec

Binary precision, default is 24.

1 - 24: 32-bit single precision 25 - 53: 64-bit double precision (synonym of DOUBLE PRECISION)

dec_prec

Decimal precision of DECFLOAT, either 16 or 34; Default is 34

precision

Numeric precision in decimal digits. From 1 to 38

scale

Scale, or number of decimals. From 0 to 38. It must be less than or equal to precision

length

The maximum length of a string, in characters, or — for BINARY and VARBINARY — bytes; optional for fixed-width character types, defaults to 1

charset

Character set

domain_or_non_array_type

Non-array types that can be used in PSQL code and casts

3.12.1.1 Use of Domains in Declarations

A domain name can be specified as the type of a PSQL parameter or local variable. The parameter or variable will inherit all domain attributes. If a default value is specified for the parameter or variable, it overrides the default value specified in the domain definition.

If the TYPE OF clause is added before the domain name, only the data type of the domain is used: any of the other attributes of the domain — NOT NULL constraint, CHECK constraints, default value — are neither checked nor used. However, if the domain is of a text type, its character set and collation sequence are always used.

3.12.1.2 Use of Column Type in Declarations

Input and output parameters or local variables can also be declared using the data type of columns in existing tables and views. The TYPE OF COLUMN clause is used for that, specifying relationname.columnname as its argument.

When TYPE OF COLUMN is used, the parameter or variable inherits only the data type and — for string types — the character set and collation sequence. The constraints and default value of the column are ignored.

3.12.2 BLOB Data Types Syntax

The BLOB data types hold binary, character or custom format data of unspecified size. For more information, see Section 3.7, Binary Data Types.

BLOB Data Types Syntax

  1. <blob_datatype> ::=
  2. BLOB [SUB_TYPE {subtype_num | subtype_name}]
  3. [SEGMENT SIZE seglen] [CHARACTER SET charset]
  4. | BLOB [(seglen [, subtype_num])]

Table 3.12.2.1 Arguments for the Blob Data Types Syntax

ArgumentDescription

charset

Character set (ignored for sub-types other than TEXT/1)

subtype_num

BLOB subtype number

subtype_name

BLOB subtype mnemonic name; this can be TEXT, BINARY, or one of the (other) standard or custom names defined in RDB$TYPES for RDB$FIELD_NAME = ‘RDB$FIELD_SUB_TYPE’.

seglen

Segment size, cannot be greater than 65,535, defaults to 80 when not specified. See also Segment Size

3.12.3 Array Data Types Syntax

The array data types hold multiple scalar values in a single or multi-dimensional array. For more information, see Section 3.8, Array Types

Array Data Types Syntax

  1. <array_datatype> ::=
  2. {SMALLINT | INT[EGER] | BIGINT | INT128} <array_dim>
  3. | {REAL | FLOAT [(bin_prec)] | DOUBLE PRECISION} <array_dim>
  4. | DECFLOAT [(dec_prec)]
  5. | BOOLEAN <array_dim>
  6. | {DATE | TIME | TIMESTAMP} <array_dim>
  7. | {DECIMAL | NUMERIC} [(precision [, scale])] <array_dim>
  8. | {VARCHAR | {CHAR | CHARACTER} VARYING} (length)
  9. <array_dim> [CHARACTER SET charset]
  10. | {CHAR | CHARACTER} [(length)] <array_dim>
  11. [CHARACTER SET charset]
  12. | {NCHAR | NATIONAL {CHARACTER | CHAR}} VARYING (length)
  13. <array_dim>
  14. | {NCHAR | NATIONAL {CHARACTER | CHAR}}
  15. [(length)] <array_dim>
  16. | BINARY [(length)] <array_dim>
  17. | {VARBINARY | BINARY VARYING} (length) <array_dim>
  18. <array_dim> ::= '[' [m:]n [,[m:]n ...] ']'

Table 3.12.3.1 Arguments for the Array Data Types Syntax

ArgumentDescription

array_dim

Array dimensions

bin_prec

Binary precision, default is 24.

1 - 24: 32-bit single precision 25 - 53: 64-bit double precision (synonym of DOUBLE PRECISION)

dec_prec

Decimal precision of DECFLOAT, either 16 or 34; default is 34

precision

Numeric precision in decimal digits. From 1 to 38

scale

Scale, or number of decimals. From 0 to 38. It must be less than or equal to precision

length

The maximum length of a string, in characters, or — for BINARY and VARBINARY — bytes; optional for fixed-width character types, defaults to 1

charset

Character set

m, n

Integer numbers defining the index range of an array dimension