Skip to main content
Converts an input into the specified type. For example, cast (input as BIGINT) converts the input into a BIGINT value. From v2.4, the database supports conversion to the ARRAY type. Note CAST(input AS CHAR(N)) truncates the result to the first N characters, consistent with MySQL. For example, CAST(1775580223839 AS CHAR(10)) returns 1775580223. CAST(input AS CHAR) without a length and CAST(input AS VARCHAR(N)) are not truncated.

Syntax

Parameters

input: the data you want to convert. type: the destination data type.

Return value

Returns a value whose data type is the same as type.

Examples

Example 1: common data conversions
Text
Example 2: Same conversions using the :: shorthand.
Text
:: is equivalent to CAST(input AS type) and uses the database cast semantics. Warning If a view or materialized view DDL uses ::, the saved original definition can contain ::. Such definitions are not backward compatible with older versions or tools that do not parse the shorthand syntax. Example 3: Convert the input into ARRAY.
Text
Example 4: Convert data during loading.
Note If the original value is a floating-point value (such as 12.0), it will be converted to NULL. If you want to forcibly convert this type into BIGINT, see the following example:
text