Fractional seconds in interval units
Vertica supports intervals in milliseconds (hh:mm:ss:ms), where 01:02:03:25 represents 1 hour, 2 minutes, 3 seconds, and 025 milliseconds. Milliseconds are converted to fractional seconds as in the following example, which returns 1 day, 2 hours, 3 minutes, 4 seconds, and 25.5 milliseconds:
=> SELECT INTERVAL '1 02:03:04:25.5';
?column?
------------
1 day 02:03:04.0255
Vertica allows fractional minutes. The fractional minutes are rounded into seconds:
=> SELECT INTERVAL '10.5 minutes';
?column?
------------
00:10:30
=> select interval '10.659 minutes';
?column?
-------------
00:10:39.54
=> select interval '10.3333333333333 minutes';
?column?
----------
00:10:20
Considerations
-
An
INTERVALcan include only the subset of units that you need; however, year/month intervals represent calendar years and months with no fixed number of days, so year/month interval values cannot include days, hours, minutes. When year/month values are specified for day/time intervals, the intervals extension assumes 30 days per month and 365 days per year. Since the length of a given month or year varies, day/time intervals are never output as months or years, only as days, hours, minutes, and so on. -
Day/time and year/month intervals are logically independent and cannot be combined with or compared to each other. In the following example, an interval-literal that contains
DAYScannot be combined with theYEAR TO MONTHtype:=> SELECT INTERVAL '1 2 3' YEAR TO MONTH; ERROR 3679: Invalid input syntax for interval year to month: "1 2 3" -
Vertica accepts intervals up to 2^63 – 1 microseconds or months (about 18 digits).
-
INTERVAL YEAR TO MONTHcan be used in an analytic RANGE window when theORDER BYcolumn type isTIMESTAMP/TIMESTAMP WITH TIMEZONE, orDATE. UsingTIME/TIME WITH TIMEZONEare not supported. -
You can use
INTERVAL DAY TO SECONDwhen theORDER BYcolumn type isTIMESTAMP/TIMESTAMP WITH TIMEZONE,DATE, andTIME/TIME WITH TIMEZONE.
Examples
Examples in this section assume that INTERVALSTYLE is set to PLAIN , so results omit subtype units. Interval values that omit an interval qualifier use the default to DAY TO SECOND(6).
SELECT INTERVAL '00:2500:00';1 17:40SELECT INTERVAL '2500' MINUTE TO SECOND;2500SELECT INTERVAL '2500' MINUTE;2500SELECT INTERVAL '28 days 3 hours' HOUR TO SECOND;675:00SELECT INTERVAL(3) '28 days 3 hours';28 03:00SELECT INTERVAL(3) '28 days 3 hours 1.234567';28 03:01:14.074SELECT INTERVAL(3) '28 days 3 hours 1.234567 sec';28 03:00:01.235SELECT INTERVAL(3) '28 days 3.3 hours' HOUR TO SECOND;675:18SELECT INTERVAL(3) '28 days 3.35 hours' HOUR TO SECOND;675:21SELECT INTERVAL(3) '28 days 3.37 hours' HOUR TO SECOND;675:22:12SELECT INTERVAL '1.234567 days' HOUR TO SECOND;29:37:46.5888SELECT INTERVAL '1.23456789 days' HOUR TO SECOND;29:37:46.665696SELECT INTERVAL(3) '1.23456789 days' HOUR TO SECOND;29:37:46.666SELECT INTERVAL(3) '1.23456789 days' HOUR TO SECOND(2);29:37:46.67SELECT INTERVAL(3) '01:00:01.234567' as "one hour+";01:00:01.235SELECT INTERVAL(3) '01:00:01.234567' = INTERVAL(3) '01:00:01.234567';tSELECT INTERVAL(3) '01:00:01.234567' = INTERVAL '01:00:01.234567';fSELECT INTERVAL(3) '01:00:01.234567' = INTERVAL '01:00:01.234567' HOUR TO SECOND(3);tSELECT INTERVAL(3) '01:00:01.234567' = INTERVAL '01:00:01.234567'MINUTE TO SECOND(3);tSELECT INTERVAL '255 1.1111' MINUTE TO SECOND(3);255:01.111SELECT INTERVAL '@ - 5 ago';5SELECT INTERVAL '@ - 5 minutes ago';00:05SELECT INTERVAL '@ 5 minutes ago';-00:05SELECT INTERVAL '@ ago -5 minutes';00:05SELECT DATE_PART('month', INTERVAL '2-3' YEAR TO MONTH);3SELECT FLOOR((TIMESTAMP '2005-01-17 10:00' - TIMESTAMP '2005-01-01') / INTERVAL '7');2