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 BPCHARCMP
Confronta il valore di due stringhe e restituisce un integer. Se le stringhe sono identiche, la funzione restituisce 0. Se la prima stringa è alfabeticamente posteriore, la funzione restituisce 1. Se la seconda stringa è maggiore, la funzione restituisce -1.
Per i caratteri multibyte, il confronto si basa sulla codifica dei byte.
Sinonimo di Funzione BTTEXT_PATTERN_CMP.
Sintassi
BPCHARCMP(string1, string2)
Argomenti
- string1
-
Una stringa
CHARo una stringaVARCHAR. - string2
-
Una stringa
CHARo una stringaVARCHAR.
Tipo restituito
INTEGER
Esempi
Gli esempi seguenti utilizzano la tabella USERS dal database di esempio di TICKIT. Per ulteriori informazioni, consulta Database di esempio.
Per determinare se il nome di un utente è alfabeticamente maggiore rispetto al cognome dell'utente per le prime dieci voci nella tabella USERS, utilizza l'esempio seguente. È possibile vedere che per le voci in cui la stringa per FIRSTNAME è successiva in ordine alfabetico rispetto a LASTNAME, la funzione restituisce 1. Se LASTNAME in ordine alfabetico viene dopo FIRSTNAME, la funzione restituisce -1.
SELECT userid, firstname, lastname, BPCHARCMP(firstname, lastname) FROM users ORDER BY 1, 2, 3, 4 LIMIT 10;+--------+-----------+-----------+-----------+ | userid | firstname | lastname | bpcharcmp | +--------+-----------+-----------+-----------+ | 1 | Rafael | Taylor | -1 | | 2 | Vladimir | Humphrey | 1 | | 3 | Lars | Ratliff | -1 | | 4 | Barry | Roy | -1 | | 5 | Reagan | Hodge | 1 | | 6 | Victor | Hernandez | 1 | | 7 | Tamekah | Juarez | 1 | | 8 | Colton | Roy | -1 | | 9 | Mufutau | Watkins | -1 | | 10 | Naida | Calderon | 1 | +--------+-----------+-----------+-----------+
Per restituire tutte le voci nella tabella USERS in cui la funzione restituisce 0, utilizza l'esempio seguente. La funzione restituisce 0 quando FIRSTNAME è identico a LASTNAME.
SELECT userid, firstname, lastname, BPCHARCMP(firstname, lastname) FROM users WHERE BPCHARCMP(firstname, lastname)=0 ORDER BY 1, 2, 3, 4;+--------+-----------+----------+-----------+ | userid | firstname | lastname | bpcharcmp | +--------+-----------+----------+-----------+ | 62 | Chase | Chase | 0 | | 4008 | Whitney | Whitney | 0 | | 12516 | Graham | Graham | 0 | | 13570 | Harper | Harper | 0 | | 16712 | Cooper | Cooper | 0 | | 18359 | Chase | Chase | 0 | | 27530 | Bradley | Bradley | 0 | | 31204 | Harding | Harding | 0 | +--------+-----------+----------+-----------+