-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
time
214 lines (169 loc) · 3.29 KB
/
time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# LogicTest: default parallel-stmts distsql
# Note that the odd '0000-01-01 hh:mi:ss +0000 UTC' result format is an
# artifact of how pq displays TIMEs.
query T
SELECT '12:00:00':::TIME;
----
0000-01-01 12:00:00 +0000 UTC
query T
SELECT '12:00:00.456':::TIME;
----
0000-01-01 12:00:00.456 +0000 UTC
query T
SELECT '00:00:00':::TIME;
----
0000-01-01 00:00:00 +0000 UTC
query T
SELECT '23:59:59.999999':::TIME;
----
0000-01-01 23:59:59.999999 +0000 UTC
statement error could not parse
SELECT '24:00:00':::TIME;
# Timezone should be ignored.
query T
SELECT '12:00:00-08:00':::TIME;
----
0000-01-01 12:00:00 +0000 UTC
# Casting
query T
SELECT '12:00:00'::TIME;
----
0000-01-01 12:00:00 +0000 UTC
# Comparison
query B
SELECT '12:00:00':::TIME = '12:00:00':::TIME
----
true
query B
SELECT '12:00:00':::TIME = '12:00:00.000000':::TIME
----
true
query B
SELECT '12:00:00':::TIME = '12:00:00.000001':::TIME
----
false
query B
SELECT '12:00:00':::TIME < '12:00:00.000001':::TIME
----
true
query B
SELECT '12:00:00':::TIME < '12:00:00':::TIME
----
false
query B
SELECT '12:00:00':::TIME < '11:59:59.999999':::TIME
----
false
query B
SELECT '12:00:00':::TIME > '11:59:59.999999':::TIME
----
true
query B
SELECT '12:00:00':::TIME > '12:00:00':::TIME
----
false
query B
SELECT '12:00:00':::TIME > '12:00:00.000001':::TIME
----
false
query B
SELECT '12:00:00':::TIME <= '12:00:00':::TIME
----
true
query B
SELECT '12:00:00':::TIME >= '12:00:00':::TIME
----
true
query B
SELECT '12:00:00':::TIME IN ('12:00:00');
----
true
query B
SELECT '12:00:00':::TIME IN ('00:00:00');
----
false
# Arithmetic
query T
SELECT '12:00:00':::TIME + '1s':::INTERVAL
----
0000-01-01 12:00:01 +0000 UTC
query T
SELECT '23:59:59':::TIME + '1s':::INTERVAL
----
0000-01-01 00:00:00 +0000 UTC
query T
SELECT '12:00:00':::TIME + '1d':::INTERVAL
----
0000-01-01 12:00:00 +0000 UTC
query T
SELECT '1s':::INTERVAL + '12:00:00':::TIME
----
0000-01-01 12:00:01 +0000 UTC
query T
SELECT '12:00:00':::TIME - '1s':::INTERVAL
----
0000-01-01 11:59:59 +0000 UTC
query T
SELECT '00:00:00':::TIME - '1s':::INTERVAL
----
0000-01-01 23:59:59 +0000 UTC
query T
SELECT '12:00:00':::TIME - '1d':::INTERVAL
----
0000-01-01 12:00:00 +0000 UTC
query T
SELECT '12:00:00':::TIME - '11:59:59':::TIME
----
1s
query T
SELECT '11:59:59':::TIME - '12:00:00':::TIME
----
-1s
# Storage
statement ok
CREATE TABLE times (t time PRIMARY KEY)
statement ok
INSERT INTO times VALUES
('00:00:00'),
('00:00:00.000001'),
('11:59:59.999999'),
('12:00:00'),
('12:00:00.000001'),
('23:59:59.999999')
query T
SELECT * FROM times ORDER BY t
----
0000-01-01 00:00:00 +0000 UTC
0000-01-01 00:00:00.000001 +0000 UTC
0000-01-01 11:59:59.999999 +0000 UTC
0000-01-01 12:00:00 +0000 UTC
0000-01-01 12:00:00.000001 +0000 UTC
0000-01-01 23:59:59.999999 +0000 UTC
statement ok
CREATE TABLE arrays (times TIME[])
statement ok
INSERT INTO arrays VALUES
(ARRAY[]),
(ARRAY['00:00:00']),
(ARRAY['00:00:00', '12:00:00.000001'])
query T rowsort
SELECT * FROM arrays
----
{}
{00:00:00}
{00:00:00,12:00:00.000001}
# Built-ins
query I
SELECT extract(hour from time '12:00:00')
----
12
query I
SELECT extract(microsecond from time '12:00:00.123456')
----
123456
query I
SELECT extract(epoch from time '12:00:00')
----
43200
query error extract\(\): unsupported timespan: day
SELECT extract(day from time '12:00:00')