Funzione TIMESTAMP_CMP - Amazon Redshift

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 TIMESTAMP_CMP

Confronta il valore di due timestamp e restituisce un intero. Se i timestamp sono identici, la funzione restituisce 0. Se il primo timestamp è maggiore, la funzione restituisce 1. Se il secondo timestamp è maggiore, la funzione restituisce -1.

Sintassi

TIMESTAMP_CMP(timestamp1, timestamp2)

Argomenti

timestamp1

Una colonna di tipo di dati TIMESTAMP o un'espressione che restituisce un tipo TIMESTAMP.

timestamp2

Una colonna di tipo di dati TIMESTAMP o un'espressione che restituisce un tipo TIMESTAMP.

Tipo restituito

INTEGER

Esempi

Gli esempi seguenti confrontano i timestamp e mostrano i risultati del confronto.

SELECT TIMESTAMP_CMP('2008-01-24 06:43:29', '2008-01-24 06:43:29'), TIMESTAMP_CMP('2008-01-24 06:43:29', '2008-02-18 02:36:48'), TIMESTAMP_CMP('2008-02-18 02:36:48', '2008-01-24 06:43:29'); timestamp_cmp | timestamp_cmp | timestamp_cmp ---------------+---------------+--------------- 0 | -1 | 1

L'esempio seguente confronta LISTTIME e SALETIME per un elenco. Il valore di TIMESTAMP_CMP è -1 per tutti i risultati in quanto il timestamp della vendita è successivo al timestamp del risultato:

select listing.listid, listing.listtime, sales.saletime, timestamp_cmp(listing.listtime, sales.saletime) from listing, sales where listing.listid=sales.listid order by 1, 2, 3, 4 limit 10; listid | listtime | saletime | timestamp_cmp --------+---------------------+---------------------+--------------- 1 | 2008-01-24 06:43:29 | 2008-02-18 02:36:48 | -1 4 | 2008-05-24 01:18:37 | 2008-06-06 05:00:16 | -1 5 | 2008-05-17 02:29:11 | 2008-06-06 08:26:17 | -1 5 | 2008-05-17 02:29:11 | 2008-06-09 08:38:52 | -1 6 | 2008-08-15 02:08:13 | 2008-08-31 09:17:02 | -1 10 | 2008-06-17 09:44:54 | 2008-06-26 12:56:06 | -1 10 | 2008-06-17 09:44:54 | 2008-07-10 02:12:36 | -1 10 | 2008-06-17 09:44:54 | 2008-07-16 11:59:24 | -1 10 | 2008-06-17 09:44:54 | 2008-07-22 02:23:17 | -1 12 | 2008-07-25 01:45:49 | 2008-08-04 03:06:36 | -1 (10 rows)

Questo esempio mostra che TIMESTAMP_CMP restituisce 0 per timestamp identici:

select listid, timestamp_cmp(listtime, listtime) from listing order by 1 , 2 limit 10; listid | timestamp_cmp --------+--------------- 1 | 0 2 | 0 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0 8 | 0 9 | 0 10 | 0 (10 rows)