INTERVAL_CMP function - Amazon Redshift

INTERVAL_CMP function

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal. For more information, see Examples of interval literals without qualifier syntax.

Syntax

INTERVAL_CMP(interval1, interval2)

Arguments

interval1

An interval literal value.

interval2

An interval literal value.

Return type

INTEGER

Examples

The following example compares the value of 3 days to 1 year.

select interval_cmp('3 days','1 year'); interval_cmp -------------- -1

This example compares the value 7 days to 1 week.

select interval_cmp('7 days','1 week'); interval_cmp -------------- 0

The following example compares the value of 1 year to 3 days.

select interval_cmp('1 year','3 days'); interval_cmp -------------- 1
  翻译: