Categories:

Semi-structured and structured data functions (Cast)

AS_BINARY¶

Casts a VARIANT value to a BINARY value.

See also:

AS_<object_type>

Syntax¶

AS_BINARY( <variant_expr> )
Copy

Arguments¶

variant_expr

An expression that evaluates to a value of type VARIANT.

Returns¶

The function returns a value of type BINARY or NULL:

  • If the type of the value in the variant_expr argument is BINARY, the function returns a value of type BINARY.

  • If the type of the value in the variant_expr argument doesn’t match the type of the output value, the function returns NULL.

  • If the variant_expr argument is NULL, the function returns NULL.

Examples¶

Create a table and load data into it:

CREATE OR REPLACE TABLE as_binary_example (binary1 VARIANT);

INSERT INTO as_binary_example (binary1)
  SELECT TO_VARIANT(TO_BINARY('F0A5'));
Copy

Use the AS_BINARY function in a query to cast a VARIANT value to a BINARY value:

SELECT AS_BINARY(binary1) AS binary_value
  FROM as_binary_example;
Copy
+--------------+
| BINARY_VALUE |
|--------------|
| F0A5         |
+--------------+