All Products
Search
Document Center

Realtime Compute for Apache Flink:Data type conversion

Last Updated:Mar 26, 2026

Realtime Compute for Apache Flink supports both implicit and explicit type conversions in Flink SQL, extending the standard Apache Flink data types. This topic describes the Legacy-Cast behavior settings and the full type conversion support matrix.

Usage notes

Legacy-Cast behavior

Realtime Compute for Apache Flink enables Legacy-Cast behavior by default. This setting controls how CAST operations behave when a conversion fails.

ParameterDefault (Realtime Compute for Apache Flink)Default (Apache Flink)Introduced in
table.exec.legacy-cast-behaviourenableddisabledFlink 1.15

When table.exec.legacy-cast-behaviour is enabled, a cast from a source data type to a target type may cause precision loss, value overflow, or return null.

CAST and TRY_CAST behavior

CAST

By default (Legacy-Cast enabled), CAST returns null when a conversion exception occurs instead of throwing an error. To make jobs fail explicitly on conversion exceptions, set table.exec.legacy-cast-behaviour=disabled.

CAST('42' AS INT)            -- returns 42 of type INT
CAST(NULL AS VARCHAR)        -- returns NULL of type VARCHAR
-- With table.exec.legacy-cast-behaviour=disabled:
CAST('non-number' AS INT)   -- throws an explicit error

TRY_CAST

TRY_CAST always returns null on conversion exceptions without failing the job. This behavior is equivalent to CAST when table.exec.legacy-cast-behaviour=enabled.

TRY_CAST('42' AS INT)           -- returns 42 of type INT
TRY_CAST(NULL AS VARCHAR)       -- returns NULL of type VARCHAR
TRY_CAST('non-number' AS INT)   -- returns NULL of type INT

Null value handling

To handle null values explicitly, use the cast(null as target_type) syntax. For example:

cast(null as varchar)

This avoids unexpected results such as the "NULL" string or conversion exceptions.

Type conversion support matrix

The following table shows which type conversions are supported. I means implicit conversion is supported. E means only explicit conversion is supported. - means conversion is not supported.

Input type \ Target typenullbooleantinyintsmallintintbigintdecimalfloatdoubleintervaldatetimetimestamp[var]char[var]binaryvariantbitmap
nullIIIIIIIIIIIIIIIII
boolean-IEEEEEEE----I-E-
tinyint-EIIIIIIIE--EI-E-
smallint-EIIIIIIIE--EI-E-
int-EIIIIIIIE--EI-E-
bigint-EIIIIIIIE--EI-E-
decimal-EIIIIIIIE--EI-E-
float-EIIIIIII---EI-E-
double-EIIIIIII---EI-E-
interval--EEEEE--I---E-E-
date----------I-II-E-
time-----------IEI-E-
timestamp--EEEEEEE-IEII-E-
[var]char-EIIIIIIIIIIIIIE-
[var]binary----------EEEIIE-
variant-EEEEEEEEEEEEEEI-
bitmap-------------EE-I

References

For the SQL data types supported by the Apache Flink community, see Community Flink SQL data types.