Amazon Redshift non supporterà più la creazione di nuove UDF Python a partire dal 1º novembre 2025. Se desideri utilizzare le UDF Python, creale prima di tale data. Le UDF Python esistenti continueranno a funzionare normalmente. Per ulteriori informazioni, consulta il post del blog
Funzione GETBIT
GETBIT restituisce il valore in bit di un valore binario all'indice specificato.
Sintassi
GETBIT(binary_value, index)
Argomenti
- binary_value
-
Un valore binario di tipo di dati
VARBYTE. - index
-
Un numero di indice del bit nel valore binario restituito. Il valore binario è un array di bit basato su 0 che viene indicizzato dal bit più a destra (bit meno significativo) al bit più a sinistra (bit più significativo).
Tipo restituito
INTEGER
Esempi
Per restituire il bit all'indice 2 del valore binario from_hex('4d'), utilizza l'esempio seguente. La rappresentazione binaria di '4d' è 01001101.
SELECT GETBIT(FROM_HEX('4d'), 2);+--------+ | getbit | +--------+ | 1 | +--------+
Per restituire il bit in otto posizioni dell'indice del valore binario restituito da from_hex('4d'), utilizza l'esempio seguente. La rappresentazione binaria di '4d' è 01001101.
SELECT GETBIT(FROM_HEX('4d'), 7), GETBIT(FROM_HEX('4d'), 6), GETBIT(FROM_HEX('4d'), 5), GETBIT(FROM_HEX('4d'), 4), GETBIT(FROM_HEX('4d'), 3), GETBIT(FROM_HEX('4d'), 2), GETBIT(FROM_HEX('4d'), 1), GETBIT(FROM_HEX('4d'), 0);+--------+--------+--------+--------+--------+--------+--------+--------+ | getbit | getbit | getbit | getbit | getbit | getbit | getbit | getbit | +--------+--------+--------+--------+--------+--------+--------+--------+ | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | +--------+--------+--------+--------+--------+--------+--------+--------+