📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

ARRAY_FILTER



Filters elements from a JSON array based on a specified Lambda expression, returning only the elements that satisfy the condition. For more information about Lambda expression, see Lambda Expressions.

Syntax

ARRAY_FILTER(<json_array>, <lambda_expression>)

Return Type

JSON array.

Examples

This example filters the array to return only the strings that start with the letter a, resulting in ["apple", "avocado"]:

SELECT ARRAY_FILTER( ['apple', 'banana', 'avocado', 'grape'], d -> d::String LIKE 'a%' ); -[ RECORD 1 ]----------------------------------- array_filter(['apple', 'banana', 'avocado', 'grape'], d -> d::STRING LIKE 'a%'): ["apple","avocado"]

Was this page helpful?