Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊,請參閱部落格文章
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ARRAY_EXCEPT 函數
保留來自第二個陣列中不存在之第一個陣列的元素,以傳回兩個陣列之間的差異。函數是 NULL 安全的,這表示它將 NULLs 視為已知物件。
語法
ARRAY_EXCEPT( array1, array2 [, distinct] )
引數
- array1
-
指定第一個陣列的 SUPER 表達式。
- array2
-
指定第二個陣列的 SUPER 表達式。
- distinct
-
布林值,指定是否僅傳回不同的元素:
- distinct = 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.
- distinct = 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)
NULLs視為已知物件。
SELECT ARRAY_EXCEPT(ARRAY('a',NULL), ARRAY(NULL)); array_except -------------- ["a"] (1 row)