函數傳 ARRAY_CONTAINS 回一個布林值,指示陣列是否包含指定的值。 您可以使用函數內的布林運算式來檢查物件的部分或完整相符。
語法
ARRAY_CONTAINS(<array_expr>, <expr> [, <bool_expr>])
Arguments
| Description | |
|---|---|
array_expr |
陣列運算式。 |
expr |
要在陣列內搜尋的運算式。 |
bool_expr |
布林運算式,指出搜尋是否應檢查部分相符 (true) 或完全相符 (false)。 若未指定,則預設值為 false。 |
傳回類型
傳回布林值。
範例
本節包含如何使用此查詢語言建構的範例。
陣列包含範例
在此範例中,函數 ARRAY_CONTAINS 用於檢查陣列中是否存在值和物件。
SELECT VALUE {
containsItem: ARRAY_CONTAINS(["coats", "jackets", "sweatshirts"], "coats"),
missingItem: ARRAY_CONTAINS(["coats", "jackets", "sweatshirts"], "hoodies"),
containsFullMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shirts", color: "blue" }),
missingFullMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shirts" }),
containsPartialMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shirts" }, true),
missingPartialMatchObject: ARRAY_CONTAINS([{ category: "shirts", color: "blue" }], { category: "shorts", color: "blue" }, true)
}
[
{
"containsItem": true,
"missingItem": false,
"containsFullMatchObject": true,
"missingFullMatchObject": false,
"containsPartialMatchObject": true,
"missingPartialMatchObject": false
}
]
備註
- 此功能受益於範圍索引的使用。 如需詳細資訊,請參閱 範圍索引。