Skip to main content

Categories: Variant Type

TRY_VARIANT_GET Preview

Extracts a value from a VARIANT using a path expression, returning NULL if the cast fails.

Syntax

TRY_VARIANT_GET(variant VARIANT, path VARCHAR) → VARIANT

  • variant: The VARIANT value to extract from.
  • path: A path expression specifying which element to extract.

Examples

TRY_VARIANT_GET example
SELECT TRY_VARIANT_GET(PARSE_JSON('{"name": "Alice"}'), '$.name')
-- (VARIANT) "Alice"

TRY_VARIANT_GET(variant VARIANT, path VARCHAR, data_type type) → Type specified as data_type

  • variant: The VARIANT value to extract from.
  • path: A path expression specifying which element to extract.
  • data_type: The Dremio data type to cast the result to.

Examples

TRY_VARIANT_GET example
SELECT TRY_VARIANT_GET(PARSE_JSON('{"value": 42}'), '$.value' AS INT)
-- 42
TRY_VARIANT_GET example
SELECT TRY_VARIANT_GET(PARSE_JSON('{"value": "not a number"}'), '$.value' AS INT)
-- NULL

Usage Notes

TRY_VARIANT_GET behaves identically to VARIANT_GET, except that it returns NULL instead of raising an error when the cast to the target type fails.

Use TRY_VARIANT_GET when processing VARIANT data that may contain unexpected types and you want to handle errors gracefully.

See VARIANT_GET for details on path syntax and behavior with missing paths.