Skip to main content
Scalar function
A NULL value remains NULL for a supported conversion. A failed supported value conversion produces NULL.

Syntax

Scalar

Arguments

Returns

  • Type: Requested target SQL type
  • NULL behavior: A NULL value remains NULL for a supported conversion. A failed supported value conversion produces NULL.

Properties

Usage notes

  • Write the target type directly in the call. It cannot be a STRING expression that changes for each row.
  • INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
  • Not every source type can be converted to every target type. MAP-to-STRING and STRUCT-to-STRING conversions are rejected. Casting ARRAY, MAP, or STRUCT does not recursively convert its elements or fields.
  • Deterministic: The same inputs and settings produce the same result.

Examples

Typical behavior

Handle invalid values in different target types

Limitations

  • Unsupported conversions or incomplete target-type definitions can cause the query to be rejected before execution. TRY_CAST does not turn those errors into NULL.
  • CHAR and VARCHAR length limits are not enforced by this cast. Do not rely on the cast to truncate text.
Last modified on October 15, 2026