Conversion includes, but is not limited to, casting and coercion:
CAST()
function.The table below summarizes all possible CAST
s and coercions. “Coercion To” applies to all expressions of a given data type (e.g. a column).
Syntax:
CAST(expr AS typename)
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=1 AS STRING)
This results in "true"
if x
is 1
, "false"
for any other non-NULL
value, and NULL
if x
is NULL
.
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 expression x
of the following types, these rules apply:
Beam SQL coerces the result type of an expression to another type if needed to match function signatures. For example, if function func() is defined to take a single argument of type INT64 and an expression is used as an argument that has a result type of FLOAT64, then the result of the expression will be coerced to INT64 type before func() is computed.