JSON_OBJECT_KEEP_NULL (Lakehouse v1)
Crea un objeto JSON con claves y valores.
- Los argumentos son cero o más pares clave-valor (donde las claves son cadenas y los valores pueden ser de cualquier tipo).
- Si una clave es NULL, el par clave-valor se omite del objeto resultante. Sin embargo, si un valor es NULL, el par clave-valor se conserva.
- Las claves deben ser distintas entre sí, y su orden en el JSON resultante puede diferir del orden en que las especifique.
TRY_JSON_OBJECT_KEEP_NULLdevuelve un valor NULL si se produce un error al construir el objeto.
Consulte también: JSON_OBJECT
Sintaxis SQL
Sección titulada «Sintaxis SQL»JSON_OBJECT_KEEP_NULL(key1, value1[, key2, value2[, ...]])
TRY_JSON_OBJECT_KEEP_NULL(key1, value1[, key2, value2[, ...]])Tipo de retorno
Sección titulada «Tipo de retorno»Objeto JSON.
Ejemplos de SQL
Sección titulada «Ejemplos de SQL»SELECT JSON_OBJECT_KEEP_NULL();┌─────────────────────────┐│ json_object_keep_null() │├─────────────────────────┤│ {} │└─────────────────────────┘
SELECT JSON_OBJECT_KEEP_NULL('a', 3.14, 'b', 'xx', 'c', NULL);┌────────────────────────────────────────────────────────┐│ json_object_keep_null('a', 3.14, 'b', 'xx', 'c', null) │├────────────────────────────────────────────────────────┤│ {"a":3.14,"b":"xx","c":null} │└────────────────────────────────────────────────────────┘
SELECT JSON_OBJECT_KEEP_NULL('fruits', ['apple', 'banana', 'orange'], 'vegetables', ['carrot', 'celery']);┌────────────────────────────────────────────────────────────────────────────────────────────────────┐│ json_object_keep_null('fruits', ['apple', 'banana', 'orange'], 'vegetables', ['carrot', 'celery']) │├────────────────────────────────────────────────────────────────────────────────────────────────────┤│ {"fruits":["apple","banana","orange"],"vegetables":["carrot","celery"]} │└────────────────────────────────────────────────────────────────────────────────────────────────────┘
SELECT JSON_OBJECT_KEEP_NULL('key'); |1 | SELECT JSON_OBJECT_KEEP_NULL('key') | ^^^^^^^^^^^^^^^^^^ The number of keys and values must be equal while evaluating function `json_object_keep_null('key')`
SELECT TRY_JSON_OBJECT_KEEP_NULL('key');┌──────────────────────────────────┐│ try_json_object_keep_null('key') │├──────────────────────────────────┤│ NULL │└──────────────────────────────────┘