共用方式為


SETUNION - Cosmos DB 中的查詢語言 (在 Azure 和 Fabric 中)

函數會 SETUNION 傳回一組運算式,其中包含兩個收集集合中的所有運算式,且沒有重複項。

語法

SetUnion(<array_expr_1>, <array_expr_2>)

Arguments

Description
array_expr_1 運算式陣列。
array_expr_2 運算式陣列。

傳回類型

傳回運算式陣列。

範例

本節包含如何使用此查詢語言建構的範例。

靜態數組的聯集

在此範例中,函數 SetUnion 與靜態陣列一起使用,以示範聯合功能。

SELECT VALUE {
  simpleUnion: SetUnion([1, 2, 3, 4], [3, 4, 5, 6]),
  emptyUnion: SetUnion([1, 2, 3, 4], []),
  duplicatesUnion: SetUnion([1, 2, 3, 4], [1, 1, 1, 1]),
  unorderedUnion: SetUnion([1, 2, "A", "B"], ["A", 1])
}
[
  {
    "simpleUnion": [1, 2, 3, 4, 5, 6],
    "emptyUnion": [1,2,3,4],
    "duplicatesUnion": [1,2,3,4],
    "unorderedUnion": [1,2,"A","B"]
  }
]

文件中陣列屬性的聯集

在此範例中,函式會傳回兩個陣列屬性的聯集作為新屬性。

SELECT
  p.name,
  SetUnion(p.colors[0].values, p.colors[1].values) AS allColors
FROM
  products p
WHERE
  p.category = "seasonal-coats"
[
  {
    "name": "Malsca coat",
    "allColors": [
      "Cutty Sark",
      "Horizon",
      "Russet",
      "Fuscous",
      "Tacha"
    ]
  }
]

備註

  • 此函式不會使用索引。
  • 此函式不會傳回重複項。