1
- select
2
- ' 1' second,
3
- 2 seconds,
4
- ' 1' minute,
5
- 2 minutes,
6
- ' 1' hour,
7
- 2 hours,
8
- ' 1' day,
9
- 2 days,
10
- ' 1' month,
11
- 2 months,
12
- ' 1' year,
13
- 2 years;
14
-
15
- select
16
- interval ' 10-11' year to month,
17
- interval ' 10' year,
18
- interval ' 11' month;
19
-
20
- select
21
- ' 10-11' year to month,
22
- ' 10' year,
23
- ' 11' month;
24
-
25
- select
26
- interval ' 10 9:8:7.987654321' day to second,
27
- interval ' 10' day,
28
- interval ' 11' hour,
29
- interval ' 12' minute,
30
- interval ' 13' second,
31
- interval ' 13.123456789' second;
32
-
33
- select
34
- ' 10 9:8:7.987654321' day to second,
35
- ' 10' day,
36
- ' 11' hour,
37
- ' 12' minute,
38
- ' 13' second,
39
- ' 13.123456789' second;
40
-
41
- select map(1 , interval 1 day, 2 , interval 3 week);
42
-
43
- select map(1 , 1 day, 2 , 3 week);
44
-
45
- -- Interval year-month arithmetic
46
-
47
- create temporary view interval_arithmetic as
48
- select CAST(dateval AS date ), CAST(tsval AS timestamp ) from values
49
- (' 2012-01-01' , ' 2012-01-01' )
50
- as interval_arithmetic(dateval, tsval);
51
-
52
- select
53
- dateval,
54
- dateval - interval ' 2-2' year to month,
55
- dateval - interval ' -2-2' year to month,
56
- dateval + interval ' 2-2' year to month,
57
- dateval + interval ' -2-2' year to month,
58
- - interval ' 2-2' year to month + dateval,
59
- interval ' 2-2' year to month + dateval
60
- from interval_arithmetic;
61
-
62
- select
63
- dateval,
64
- dateval - ' 2-2' year to month,
65
- dateval - ' -2-2' year to month,
66
- dateval + ' 2-2' year to month,
67
- dateval + ' -2-2' year to month,
68
- - ' 2-2' year to month + dateval,
69
- ' 2-2' year to month + dateval
70
- from interval_arithmetic;
71
-
72
- select
73
- tsval,
74
- tsval - interval ' 2-2' year to month,
75
- tsval - interval ' -2-2' year to month,
76
- tsval + interval ' 2-2' year to month,
77
- tsval + interval ' -2-2' year to month,
78
- - interval ' 2-2' year to month + tsval,
79
- interval ' 2-2' year to month + tsval
80
- from interval_arithmetic;
81
-
82
- select
83
- tsval,
84
- tsval - ' 2-2' year to month,
85
- tsval - ' -2-2' year to month,
86
- tsval + ' 2-2' year to month,
87
- tsval + ' -2-2' year to month,
88
- - ' 2-2' year to month + tsval,
89
- ' 2-2' year to month + tsval
90
- from interval_arithmetic;
91
-
92
- select
93
- interval ' 2-2' year to month + interval ' 3-3' year to month,
94
- interval ' 2-2' year to month - interval ' 3-3' year to month
95
- from interval_arithmetic;
96
-
97
- select
98
- ' 2-2' year to month + ' 3-3' year to month,
99
- ' 2-2' year to month - ' 3-3' year to month
100
- from interval_arithmetic;
101
-
102
- -- Interval day-time arithmetic
103
-
104
- select
105
- dateval,
106
- dateval - interval ' 99 11:22:33.123456789' day to second,
107
- dateval - interval ' -99 11:22:33.123456789' day to second,
108
- dateval + interval ' 99 11:22:33.123456789' day to second,
109
- dateval + interval ' -99 11:22:33.123456789' day to second,
110
- - interval ' 99 11:22:33.123456789' day to second + dateval,
111
- interval ' 99 11:22:33.123456789' day to second + dateval
112
- from interval_arithmetic;
113
-
114
- select
115
- dateval,
116
- dateval - ' 99 11:22:33.123456789' day to second,
117
- dateval - ' -99 11:22:33.123456789' day to second,
118
- dateval + ' 99 11:22:33.123456789' day to second,
119
- dateval + ' -99 11:22:33.123456789' day to second,
120
- - ' 99 11:22:33.123456789' day to second + dateval,
121
- ' 99 11:22:33.123456789' day to second + dateval
122
- from interval_arithmetic;
123
-
124
- select
125
- tsval,
126
- tsval - interval ' 99 11:22:33.123456789' day to second,
127
- tsval - interval ' -99 11:22:33.123456789' day to second,
128
- tsval + interval ' 99 11:22:33.123456789' day to second,
129
- tsval + interval ' -99 11:22:33.123456789' day to second,
130
- - interval ' 99 11:22:33.123456789' day to second + tsval,
131
- interval ' 99 11:22:33.123456789' day to second + tsval
132
- from interval_arithmetic;
133
-
134
- select
135
- tsval,
136
- tsval - ' 99 11:22:33.123456789' day to second,
137
- tsval - ' -99 11:22:33.123456789' day to second,
138
- tsval + ' 99 11:22:33.123456789' day to second,
139
- tsval + ' -99 11:22:33.123456789' day to second,
140
- - ' 99 11:22:33.123456789' day to second + tsval,
141
- ' 99 11:22:33.123456789' day to second + tsval
142
- from interval_arithmetic;
143
-
144
- select
145
- interval ' 99 11:22:33.123456789' day to second + interval ' 10 9:8:7.123456789' day to second,
146
- interval ' 99 11:22:33.123456789' day to second - interval ' 10 9:8:7.123456789' day to second
147
- from interval_arithmetic;
148
-
149
- select
150
- ' 99 11:22:33.123456789' day to second + ' 10 9:8:7.123456789' day to second,
151
- ' 99 11:22:33.123456789' day to second - ' 10 9:8:7.123456789' day to second
152
- from interval_arithmetic;
153
-
154
- -- More tests for interval syntax alternatives
155
-
156
- select 30 day;
1
+ -- import interval.sql
157
2
3
+ -- the `interval` keyword can be omitted with ansi mode
4
+ select 1 year 2 days;
5
+ select ' 10-9' year to month;
6
+ select ' 20 15:40:32.99899999' day to second;
158
7
select 30 day day;
159
-
160
- select 30 day day day;
161
-
162
- select date ' 2012-01-01' - 30 day;
163
-
164
- select date ' 2012-01-01' - 30 day day;
165
-
166
- select date ' 2012-01-01' - 30 day day day;
167
-
168
- select date ' 2012-01-01' + ' -30' day;
169
-
170
- select date ' 2012-01-01' + interval ' -30' day;
171
-
172
- -- Unsupported syntax for intervals
173
-
174
- select date ' 2012-01-01' + interval (- 30 ) day;
175
-
176
- select date ' 2012-01-01' + (- 30 ) day;
177
-
178
- create temporary view t as select * from values (1 ), (2 ) as t(a);
179
-
180
- select date ' 2012-01-01' + interval (a + 1 ) day from t;
181
-
182
- select date ' 2012-01-01' + (a + 1 ) day from t;
8
+ select date ' 2012-01-01' - ' 2-2' year to month;
9
+ select 1 month - 1 day;
183
10
184
11
-- malformed interval literal with ansi mode
185
12
select 1 year to month;
186
13
select ' 1' year to second;
187
14
select 1 year ' 2-1' year to month;
15
+ select (- 30 ) day;
16
+ select (a + 1 ) day;
17
+ select 30 day day day;
0 commit comments