Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Función
Se aplica a:
Databricks SQL
Databricks Runtime 15.3 y versiones posteriores
Extrae un valor de tipo type de variantExpr, especificado por path, o NULL si no es posible convertir al tipo de destino.
Sintaxis
try_variant_get ( variantExpr, path, type )
Argumentos
-
variantExpr: expresiónVARIANT. -
path: un literalSTRINGde cadena con una expresión de ruta de acceso JSON correcta. -
type: un literalSTRINGque define el tipo.
Devoluciones
Valor de tipo type.
Si no se encuentra el objeto o no se puede convertir a type, se devuelve NULL.
Para generar un error cuando se produce un error en la conversión, use variant_get.
Ejemplos
-- Simple example
> SELECT try_variant_get(parse_json('{"key": 123, "data": [4, {"a": "hello"}, "str"]}'), '$.data[1].a', 'string')
hello
-- missing path
> SELECT try_variant_get(parse_json('{"key": 123, "data": [4, {"a": "hello"}, "str"]}'), '$.missing', 'int')
null
-- Invalid cast
> SELECT try_variant_get(parse_json('{"key": 123, "data": [4, {"a": "hello"}, "str"]}'), '$.key', 'boolean')
null
-- These are synonymous to:
> SELECT '{"key": 123, "data": [4, {"a": "hello"}, "str"]}':data[1].a ?::STRING;
hello
> SELECT '{"key": 123, "data": [4, {"a": "hello"}, "str"]}':missing ?::STRING;
null
> SELECT '{"key": 123, "data": [4, {"a": "hello"}, "str"]}':key ?::BOOLEAN;
null