-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimewise.sql
More file actions
209 lines (181 loc) · 5.32 KB
/
Copy pathtimewise.sql
File metadata and controls
209 lines (181 loc) · 5.32 KB
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
SET TIMEZONE TO MST;
SHOW integer_datetimes;
CREATE OR REPLACE FUNCTION date_properties(d date) RETURNS setof text LANGUAGE python AS
$python$
def main(d):
return ['date: ' + str(d)] + [
': '.join((attname, str(getattr(d, attname))))
for attname in [
'millennium',
'century',
'decade',
'year',
'quarter',
'week',
'month',
'day',
'dayofweek',
'dayofyear',
]
] + [
'epoch: {:.3f}'.format(d.epoch)
]
$python$;
SELECT date_properties('2000-01-01'::date);
SELECT date_properties('1000-01-01'::date);
SELECT date_properties('1000-12-30'::date);
SELECT date_properties('3000-12-30'::date);
SELECT date_properties('1-1-0001'::date);
CREATE OR REPLACE FUNCTION time_properties(d time) RETURNS setof text LANGUAGE python AS
$python$
def main(d):
return ['time: ' + str(d)] + [
': '.join((attname, str(getattr(d, attname))))
for attname in [
'hour',
'minute',
'second',
'millisecond',
'microsecond',
]
] + [
'epoch: {:.3f}'.format(d.epoch)
]
$python$;
SELECT time_properties('0:0:0.0'::time);
SELECT time_properties('23:59:59'::time);
SELECT time_properties('10:30:00.123'::time);
SELECT time_properties('12:30:35.22222'::time);
CREATE OR REPLACE FUNCTION timetz_properties(d timetz) RETURNS setof text LANGUAGE python AS
$python$
def main(d):
return ['timetz: ' + str(d)] + [
': '.join((attname, str(getattr(d, attname))))
for attname in [
'timezone',
'hour',
'minute',
'second',
'millisecond',
'microsecond',
]
] + [
'epoch: {:.3f}'.format(d.epoch)
]
$python$;
SELECT timetz_properties('0:0:0.0'::timetz);
SELECT timetz_properties('23:59:59'::timetz);
SELECT timetz_properties('10:30:00.123'::timetz);
SELECT timetz_properties('12:30:35.22222'::timetz);
SELECT timetz_properties('0:0:0.0+0700'::timetz);
SELECT timetz_properties('0:0:0.0-0700'::timetz);
SELECT timetz_properties('23:59:59+300'::timetz);
SELECT timetz_properties('23:59:59-300'::timetz);
SELECT timetz_properties('11:30:00.123+1245'::timetz);
SELECT timetz_properties('15:30:35.22222-0352'::timetz);
CREATE OR REPLACE FUNCTION timestamp_properties(d timestamp) RETURNS setof text LANGUAGE python AS
$python$
def main(d):
return ['timestamp: ' + str(d)] + [
': '.join((attname, str(getattr(d, attname))))
for attname in [
'millennium',
'century',
'decade',
'year',
'quarter',
'week',
'month',
'day',
'hour',
'minute',
'second',
'millisecond',
'microsecond',
'dayofweek',
'dayofyear',
]
] + [
'epoch: {:.3f}'.format(d.epoch)
]
$python$;
SELECT timestamp_properties('2000-01-01 0:0:0.0'::timestamp);
SELECT timestamp_properties('1990-06-01 23:59:59'::timestamp);
SELECT timestamp_properties('2020-10-10 10:30:00.123'::timestamp);
SELECT timestamp_properties('2045-12-20 12:30:35.22222'::timestamp);
SELECT timestamp_properties('2200-01-01 0:0:0.0'::timestamp);
SELECT timestamp_properties('1000-01-01 0:0:0.0'::timestamp);
SELECT timestamp_properties('1500-02-21 23:59:59'::timestamp);
SELECT timestamp_properties('2499-12-31 23:59:59'::timestamp);
SELECT timestamp_properties('2100-01-01 11:30:00.123'::timestamp);
SELECT timestamp_properties('2235-01-01 15:30:35.22222'::timestamp);
CREATE OR REPLACE FUNCTION timestamptz_properties(d timestamptz) RETURNS setof text LANGUAGE python AS
$python$
def main(d):
return ['timestamptz: ' + str(d)] + [
': '.join((attname, str(getattr(d, attname))))
for attname in [
'timezone',
'millennium',
'century',
'quarter',
'decade',
'year',
'week',
'month',
'day',
'hour',
'minute',
'second',
'millisecond',
'microsecond',
'dayofweek',
'dayofyear',
]
] + [
'epoch: {:.3f}'.format(d.epoch)
]
$python$;
SELECT timestamptz_properties('2000-01-01 0:0:0.0'::timestamptz);
SELECT timestamptz_properties('1990-06-01 23:59:59'::timestamptz);
SELECT timestamptz_properties('2020-10-10 10:30:00.123'::timestamptz);
SELECT timestamptz_properties('2045-12-20 12:30:35.22222'::timestamptz);
SELECT timestamptz_properties('2200-01-01 0:0:0.0+0800'::timestamptz);
SELECT timestamptz_properties('1000-01-01 0:0:0.0-0800'::timestamptz);
SELECT timestamptz_properties('1500-02-21 23:59:59+300'::timestamptz);
SELECT timestamptz_properties('2499-12-31 23:59:59-300'::timestamptz);
SELECT timestamptz_properties('2100-01-01 11:30:00.123+1245'::timestamptz);
SELECT timestamptz_properties('2235-01-01 15:30:35.22222-0352'::timestamptz);
CREATE OR REPLACE FUNCTION interval_properties(d interval) RETURNS setof text LANGUAGE python AS
$python$
def main(d):
return ['interval: ' + str(d)] + [
': '.join((attname, str(getattr(d, attname))))
for attname in [
'millennium',
'century',
'decade',
'year',
'quarter',
'month',
'day',
'hour',
'minute',
'second',
'millisecond',
'microsecond',
]
] + [
'epoch: {:.3f}'.format(d.epoch)
]
$python$;
SELECT interval_properties('0'::interval);
SELECT interval_properties('1 second'::interval);
SELECT interval_properties('1 day'::interval);
SELECT interval_properties('1 year'::interval);
SELECT interval_properties('4 weeks 7 days 2 hours 7 minutes 2 seconds 10232 microseconds'::interval);
SELECT interval_properties('1 month'::interval);
SELECT interval_properties('85 years'::interval);
SELECT interval_properties('1 century'::interval);
SELECT interval_properties('1 millennium'::interval);
SELECT interval_properties('3 months 6 days'::interval);