Complete the code to flatten the nested array column named 'items'.
SELECT value FROM orders, LATERAL FLATTEN(input => [1]);The FLATTEN function requires the nested array column as input. Here, 'orders.items' is the correct nested array to flatten.
Complete the code to extract the 'name' field from each element after flattening.
SELECT f.value:[1] AS item_name FROM orders, LATERAL FLATTEN(input => orders.items) f;After flattening, each element is a JSON object. To get the 'name' field, use 'f.value:name'.
Fix the error in the code to correctly flatten the nested array 'products' in the 'sales' table.
SELECT s.id, f.value FROM sales s, LATERAL FLATTEN(input => s.[1]) f;The correct nested array column is 'products'. Using 'product' or other names causes errors.
Fill both blanks to flatten the 'details' array and extract the 'price' field.
SELECT f.value:[1] AS price FROM invoices, LATERAL FLATTEN(input => invoices.[2]) f;
The nested array is 'details', and the field to extract is 'price'.
Fill all three blanks to flatten the 'attributes' array, extract 'color', and filter where 'size' is 'M'.
SELECT f.value:[1] AS color FROM products p, LATERAL FLATTEN(input => p.[2]) f WHERE f.value:[3] = 'M';
The nested array is 'attributes'. We extract 'color' and filter where 'size' equals 'M'.