When the data type for the lambda argument is explicitly specified, the array element is coerced into the specified type
before lambda invocation. For information about coercion, see Data type conversion.
When there is no data type specified for the lambda argument, its data type is derived from the input array as follows:
If the input array is semi-structured, the data type of the lambda argument is VARIANT.
If the input array is structured, the data type of the lambda argument is the data type of the array element.
For semi-structured array input, a semi-structured array is returned. For structured array input, a structured array
of the lambda expression result type is returned.
Use the TRANSFORM function to return the value of each object in an array, and add text to each one:
SELECTTRANSFORM([{'name':'Pat','value':50},{'name':'Terry','value':75},{'name':'Dana','value':25}],
c -> c:value||' is the number')AS"Return Values";
+-----------------------+|ReturnValues|%-----------------------%|[||"50 is the number",||"75 is the number",||"25 is the number"||]|+-----------------------+
Assume you have a table named orders with the columns order_id, order_date, and order_detail. The
order_detail column is an array of the line items, their purchase quantity, and subtotal. The table contains
two rows of data. The following SQL statement creates this table and inserts the rows:
Use the TRANSFORM function along with the OBJECT_DELETE function in the logic of the
lambda expression to delete the quantity element in each array from the orders table:
SELECT order_id,
order_date,TRANSFORM(o.order_detail, i ->OBJECT_DELETE(
i,'quantity'))AS order_detail_without_quantity
FROM orders o;