Επεξεργασία

Κοινή χρήση μέσω


CHOOSE (NoSQL query)

APPLIES TO: NoSQL

Returns the expression at the specified index of a list, or Undefined if the index exceeds the bounds of the list.

Syntax

CHOOSE(<numeric_expr>, <expr_1> [, <expr_N>])

Arguments

Description
numeric_expr A numeric expression, which specifies the index used to get a specific expression in the list. The starting index of the list is 1.
expr_1 The first expression in the list.
expr_N (Optional) Optional expression[s], which can contain a variable number of expressions up to the Nth item in the list.

Return types

Returns an expression, which could be of any type.

Examples

The following example uses a static list to demonstrate various return values at different indexes.

SELECT VALUE 
    CHOOSE(1, "adventure", "works", true, [1])
[
  "adventure"
]

This example uses a static list to demonstrate various return values at different indexes.

SELECT VALUE {
    index_0: CHOOSE(0, "abc", 1, true, [1]),
    index_1: CHOOSE(1, "abc", 1, true, [1]),
    index_2: CHOOSE(2, "abc", 1, true, [1]),
    index_3: CHOOSE(3, "abc", 1, true, [1]),
    index_4: CHOOSE(4, "abc", 1, true, [1]),
    index_5: CHOOSE(5, "abc", 1, true, [1])
}
[
  {
    "index_1": "abc",
    "index_2": 1,
    "index_3": true,
    "index_4": [
      1
    ]
  }
]

This final example uses an existing item in a container with three relevant fields.

[
  {
    "name": "Gremon Fins",
    "sku": "73311",
    "tags": [
      "Science Blue",
      "Turbo"
    ],
    "category": "short-fins"
  }
]

This example selects an expression from existing paths in the item.

SELECT
    CHOOSE(3, p.category, p.name, p.sku) AS barcode
FROM
    products p
WHERE
    p.category = "short-fins"
[
  {
    "barcode": "73311"
  }
]

Remarks

  • This function uses one-based list indexing. The first item in the list is referenced using the numeric index 1 instead of 0.
  • This function doesn't utilize the index.

See also