FirebirdSQL logo

Explicit Data Type Conversion

The CAST function enables explicit conversion between many pairs of data types.

Syntax
CAST (<expression> AS <target_type>)

<target_type> ::= <domain_or_non_array_type> | <array_datatype>

<domain_or_non_array_type> ::=
  !! See Scalar Data Types Syntax !!

<array_datatype> ::=
  !! See Array Data Types Syntax !!

See also CAST() in Chapter Built-in Scalar Functions.

Casting to a Domain

When you cast to a domain, any constraints declared for it are taken into account, i.e. NOT NULL or CHECK constraints.If the value does not pass the check, the cast will fail.

If TYPE OF is additionally specified — casting to its base type — any domain constraints are ignored during the cast.If TYPE OF is used with a character type (CHAR/VARCHAR), the character set and collation are retained.