TIMESTAMPTZ_CMP function - Amazon Redshift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Amazon Redshift will no longer support the creation of new Python UDFs starting November 1, 2025. If you would like to use Python UDFs, create the UDFs prior to that date. Existing Python UDFs will continue to function as normal. For more information, see the blog post .

TIMESTAMPTZ_CMP function

TIMESTAMPTZ_CMP compares the value of two timestamp with time zone values and returns an integer. If the timestamps are identical, the function returns 0. If the first timestamp is greater chronologically, the function returns 1. If the second timestamp is greater, the function returns –1.

Syntax

TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

Arguments

timestamptz1

A column of data type TIMESTAMPTZ or an expression that implicitly evaluates to a TIMESTAMPTZ type.

timestamptz2

A column of data type TIMESTAMPTZ or an expression that implicitly evaluates to a TIMESTAMPTZ type.

Return type

INTEGER

Examples

The following example compares timestamps with time zones and shows the results of the comparison.

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