Funzione TRUNC - Amazon Redshift

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 TRUNC

Tronca un TIMESTAMP e restituisce DATE.

Questa funzione può anche troncare un numero. Per ulteriori informazioni, consulta Funzione TRUNC.

Sintassi

TRUNC(timestamp)

Argomenti

timestamp

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

Per restituire un valore di timestamp con come ora, eseguire il casting del risultato della funzione su TIMESTAMP.

Tipo restituito

DATE

Esempi

Nel seguente esempio viene restituita la parte di data dal risultato della funzione SYSDATE (che restituisce un timestamp).

SELECT SYSDATE; +----------------------------+ | timestamp | +----------------------------+ | 2011-07-21 10:32:38.248109 | +----------------------------+ SELECT TRUNC(SYSDATE); +------------+ | trunc | +------------+ | 2011-07-21 | +------------+

Nell'esempio seguente viene applicata la funzione TRUNC a una colonna TIMESTAMP. Il tipo restituito è una data.

SELECT TRUNC(starttime) FROM event ORDER BY eventid LIMIT 1; +------------+ | trunc | +------------+ | 2008-01-25 | +------------+

L'esempio seguente restituisce un valore di timestamp con 00:00:00 come ora trasmessa dal risultato della funzione TRUNC su TIMESTAMP.

SELECT CAST((TRUNC(SYSDATE)) AS TIMESTAMP); +---------------------+ | trunc | +---------------------+ | 2011-07-21 00:00:00 | +---------------------+