Stay organized with collectionsSave and categorize content based on your preferences.
"Conversion" includes, but is not limited to, casting and coercion.
Casting is explicit conversion and uses theCAST()function.
Coercion is implicit conversion, which Dataflow SQL performs
automatically given the conditions described in this page.
The following table summarizes all possibleCASTand coercion possibilities
for Dataflow SQL data types. "Coercion To" applies to allexpressionsof a given data type (for example, a column).
From Type
CAST to
Coercion To
INT64
INT64 FLOAT64 STRING
FLOAT64
FLOAT64
FLOAT64
BOOL
BOOL
STRING
INT64 STRING BYTES TIMESTAMP
BYTES
BYTES STRING
TIMESTAMP
STRING TIMESTAMP
ARRAY
ARRAY
STRUCT
STRUCT
Casting
Syntax:
CAST(exprAStypename)
Cast syntax is used in a query to indicate that the result type of an
expression should be converted to some other type.
Example:
CAST(x=1ASSTRING)
This example results in"true"ifxis1,"false"for any other
non-NULLvalue, andNULLifxisNULL.
Casts between supported types that do not successfully map from the original
value to the target domain produce runtime errors. For example, casting BYTES
to STRING where the byte sequence is not valid UTF-8 results in a runtime error.
When casting an expressionxof the following types, these rules apply:
From
To
Rules when castingx
INT64
FLOAT64
Returns a close but potentially not exact
FLOAT64
value.
The original STRUCT field types can be explicitly cast to the corresponding
target STRUCT field types (as defined by field order, not field name).
Coercion
If needed to match function signatures, Dataflow SQL coerces the
result type of an expression to another type. For example, a function func() is
defined to take a single argument of type INT64. If an expression is used as an
argument that has a result type of FLOAT64, then the result of the expression is
coerced to INT64 type before func() is computed.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eConversion in Dataflow SQL includes both explicit conversion using \u003ccode\u003eCAST()\u003c/code\u003e and implicit conversion, known as coercion.\u003c/p\u003e\n"],["\u003cp\u003eCasting, which is explicit conversion, uses the \u003ccode\u003eCAST(expr AS typename)\u003c/code\u003e syntax to change the type of an expression.\u003c/p\u003e\n"],["\u003cp\u003eCoercion is the automatic implicit conversion Dataflow SQL performs to match function signature requirements, like converting a FLOAT64 to INT64 for a function that requires an INT64 input.\u003c/p\u003e\n"],["\u003cp\u003eCasting between types can result in runtime errors if the original value cannot be mapped to the target type, like casting invalid UTF-8 BYTES to STRING.\u003c/p\u003e\n"],["\u003cp\u003eWhen casting STRUCTS, the original and target STRUCTS must have the same number of fields, and each field must be explicitly castable to the corresponding field type in the target STRUCT.\u003c/p\u003e\n"]]],[],null,["# Conversion rules in Dataflow SQL\n\n\"Conversion\" includes, but is not limited to, casting and coercion.\n\n- Casting is explicit conversion and uses the `CAST()` function.\n- Coercion is implicit conversion, which Dataflow SQL performs automatically given the conditions described in this page.\n\nThe following table summarizes all possible `CAST` and coercion possibilities\nfor Dataflow SQL data types. \"Coercion To\" applies to all\n*expressions* of a given data type (for example, a column).\n\n### Casting\n\nSyntax: \n\n CAST(expr AS typename)\n\nCast syntax is used in a query to indicate that the result type of an\nexpression should be converted to some other type.\n\nExample: \n\n CAST(x=1 AS STRING)\n\nThis example results in `\"true\"` if `x` is `1`, `\"false\"` for any other\nnon-`NULL` value, and `NULL` if `x` is `NULL`.\n\nCasts between supported types that do not successfully map from the original\nvalue to the target domain produce runtime errors. For example, casting BYTES\nto STRING where the byte sequence is not valid UTF-8 results in a runtime error.\n\nWhen casting an expression `x` of the following types, these rules apply:\n\n### Coercion\n\nIf needed to match function signatures, Dataflow SQL coerces the\nresult type of an expression to another type. For example, a function func() is\ndefined to take a single argument of type INT64. If an expression is used as an\nargument that has a result type of FLOAT64, then the result of the expression is\ncoerced to INT64 type before func() is computed."]]