JSON_ARRAY (Lakehouse v1)
Crée un tableau JSON à partir des valeurs spécifiées.
Syntaxe Analyze
Section intitulée « Syntaxe Analyze »func.json_array(value1[, value2[, ...]])Exemples Analyze
Section intitulée « Exemples Analyze »func.json_array('fruits', func.json_array('apple', 'banana', 'orange'), func.json_object('price', 1.2, 'quantity', 3)) |-----------------------------------------------------------------------------------------------------------------------+["fruits",["apple","banana","orange"],{"price":1.2,"quantity":3}] |Syntaxe SQL
Section intitulée « Syntaxe SQL »JSON_ARRAY(value1[, value2[, ...]])Type de retour
Section intitulée « Type de retour »Tableau JSON.
Exemples SQL
Section intitulée « Exemples SQL »Exemples SQL 1 : création d’un tableau JSON à partir de valeurs constantes ou d’expressions
Section intitulée « Exemples SQL 1 : création d’un tableau JSON à partir de valeurs constantes ou d’expressions »SELECT JSON_ARRAY('PlaidCloud Lakehouse', 3.14, NOW(), TRUE, NULL);
json_array('databend', 3.14, now(), true, null) |--------------------------------------------------------+["PlaidCloud Lakehouse",3.14,"2023-09-06 07:23:55.399070",true,null]|
SELECT JSON_ARRAY('fruits', JSON_ARRAY('apple', 'banana', 'orange'), JSON_OBJECT('price', 1.2, 'quantity', 3));
json_array('fruits', json_array('apple', 'banana', 'orange'), json_object('price', 1.2, 'quantity', 3))|-------------------------------------------------------------------------------------------------------+["fruits",["apple","banana","orange"],{"price":1.2,"quantity":3}] |Exemples SQL 2 : création d’un tableau JSON à partir des données de la table
Section intitulée « Exemples SQL 2 : création d’un tableau JSON à partir des données de la table »CREATE TABLE products ( ProductName VARCHAR(255), Price DECIMAL(10, 2));
INSERT INTO products (ProductName, Price)VALUES ('Apple', 1.2), ('Banana', 0.5), ('Orange', 0.8);
SELECT JSON_ARRAY(ProductName, Price) FROM products;
json_array(productname, price)|------------------------------+["Apple",1.2] |["Banana",0.5] |["Orange",0.8] |