从补丁 198 开始,Amazon Redshift 将不再支持创建新的 Python UDF。现有的 Python UDF 将继续正常运行至 2026 年 6 月 30 日。有关更多信息,请参阅博客文章
ARRAY_EXCEPT 函数
通过保留第一个数组中不存在于第二个数组中的元素,返回两个数组之间的差异。该函数是 NULL 安全的,这意味着它将 NULL 视为已知对象。
语法
ARRAY_EXCEPT( array1, array2 [, distinct] )
参数
- array1
-
一个用于指定第一个数组的 SUPER 表达式。
- array2
-
一个用于指定第二个数组的 SUPER 表达式。
- 区分
-
一个布尔值,用于指定是否只返回不同的元素:
- 区分 = FALSE: Multi-set semantics apply. Each occurrence of an element in the first array is matched against occurrences in the second array. If the first array has more occurrences of an element than the second array, the extra occurrences are preserved in the result.
- 区分 = TRUE: Set semantics apply. Both arrays are treated as sets, ignoring duplicate elements. Elements from the first array are removed if they exist anywhere in the second array, regardless of occurrence count.
默认值为 FALSE。
返回类型
ARRAY_EXCEPT 函数返回 SUPER 类型。
示例
以下示例显示 ARRAY_EXCEPT 函数。
SELECT ARRAY_EXCEPT(ARRAY('a','b','c'), ARRAY('b','c','d')); array_except -------------- ["a"] (1 row)
多集语义:
SELECT ARRAY_EXCEPT(ARRAY('b','b','b','b'), ARRAY('b','b')); array_except -------------- ["b","b"] (1 row)
集语义:
SELECT ARRAY_EXCEPT(ARRAY('a','b','b'), ARRAY('b'), TRUE); array_except -------------- ["a"] (1 row)
NULL 被视为已知对象。
SELECT ARRAY_EXCEPT(ARRAY('a',NULL), ARRAY(NULL)); array_except -------------- ["a"] (1 row)