Amazon Redshift non supporterà più la creazione di nuovi Python UDFs a partire dalla Patch 198. Python esistente UDFs continuerà a funzionare fino al 30 giugno 2026. Per ulteriori informazioni, consulta il post del blog
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Funzione ARRAY_POSITIONS
Restituisce una matrice di posizioni (indici) in cui l'elemento specificato appare nell'array di input. Gli indici sono basati su 0, dove 0 indica il primo elemento, 1 indica il secondo elemento e così via. Restituisce una matrice vuota se l'elemento non viene trovato.
Sintassi
ARRAY_POSITIONS( array, value [, null_match] )
Arguments (Argomenti)
- matrice
-
Un'espressione SUPER che specifica l'array in cui effettuare la ricerca.
- value
-
Un valore che specifica l'elemento da cercare.
- null_match
-
Un valore booleano che specifica come vengono gestiti i valori NULL:
- null_match = FALSE: Searching for NULL returns NULL. If the array contains NULL values and no match is found for a non-NULL search value, returns NULL.
- null_match = TRUE: NULLs are treated as valid, searchable elements. If the array contains NULL values and no match is found for a non-NULL search value, it returns an empty array.
Il valore predefinito è TRUE.
La gestione predefinita dei NULL può essere specificata anche dall'opzione di configurazione:
-- same as null_match = TRUE SET default_array_search_null_handling to TRUE;
Tipo restituito
La funzione ARRAY_POSITIONS restituisce un tipo SUPER.
Esempio
Gli esempi seguenti mostrano la funzione ARRAY_POSITIONS.
SELECT ARRAY_POSITIONS(ARRAY('red', 'green', 'red'), 'red'); array_positions ----------------- [0,2] (1 row) SELECT ARRAY_POSITIONS(ARRAY(1, 2, 3), 4); array_positions ----------------- [] (1 row)
Gli esempi seguenti mostrano il comportamento della funzione con null_match impostato su TRUE.
SET default_array_search_null_handling to TRUE; -- NULL search is enabled SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green', NULL), NULL); array_positions ----------------- [1,3] (1 row) -- The array can contain NULLs SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green'), 'blue', TRUE); array_positions ----------------- [] (1 row)
Gli esempi seguenti mostrano il comportamento della funzione con null_match impostato su FALSE. Nota che la specifica del comportamento null_match nella funzione sovrascriverà l'impostazione di configurazione predefinita.
-- same as null_match = TRUE SET default_array_search_null_handling to TRUE; -- NULL search is disabled. The default behavior is overridden SELECT ARRAY_POSITIONS(ARRAY('red', 'green'), NULL, FALSE); array_positions ----------------- (1 row) -- same as null_match = FALSE SET default_array_search_null_handling to FALSE; -- The array contains NULL and a match is found SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green'), 'green'); array_positions ----------------- [2] (1 row) -- The array contains NULL but no match is found SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green'), 'blue'); array_positions ----------------- (1 row)