Função ARRAY_EXCEPT - Amazon Redshift

O Amazon Redshift não permitirá mais a criação de UDFs do Python a partir do Patch 198. As UDFs do Python existentes continuarão a funcionar normalmente até 30 de junho de 2026. Para ter mais informações, consulte a publicação de blog .

Função ARRAY_EXCEPT

Exibe a diferença entre duas matrizes, mantendo elementos da primeira que não existem na segunda. A função é à prova de NULL, o que significa que os NULLs são tratados como objetos conhecidos.

Sintaxe

ARRAY_EXCEPT( array1, array2 [, distinct] )

Argumentos

array1

Uma expressão SUPER que especifica a primeira matriz.

array2

Uma expressão SUPER que especifica a segunda matriz.

distinct

Um valor booliano que especifica se somente elementos distintos devem ser exibidos:

  • 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.

O padrão é FALSE.

Tipo de retorno

A função ARRAY_EXCEPT exibe um tipo SUPER.

Exemplo

Os exemplos a seguir mostram a função ARRAY_EXCEPT.

SELECT ARRAY_EXCEPT(ARRAY('a','b','c'), ARRAY('b','c','d')); array_except -------------- ["a"] (1 row)

Semântica de vários conjuntos:

SELECT ARRAY_EXCEPT(ARRAY('b','b','b','b'), ARRAY('b','b')); array_except -------------- ["b","b"] (1 row)

Semântica de conjunto:

SELECT ARRAY_EXCEPT(ARRAY('a','b','b'), ARRAY('b'), TRUE); array_except -------------- ["a"] (1 row)

Os NULLs são tratados como objeto conhecido.

SELECT ARRAY_EXCEPT(ARRAY('a',NULL), ARRAY(NULL)); array_except -------------- ["a"] (1 row)

Consulte também