MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestFunctionsDateTime

Function TestFunctionsDateTime

tests/integration/functions_test.go:146–196  ·  view source on GitHub ↗

TestFunctionsDateTime tests date/time functions

(t *testing.T)

Source from the content-addressed store, hash-verified

144
145// TestFunctionsDateTime tests date/time functions
146func TestFunctionsDateTime(t *testing.T) {
147 tests := []QueryTest{
148 // Current date/time (test that they work, not specific values)
149 {Name: "current_date_not_null", Query: "SELECT current_date IS NOT NULL"},
150 {Name: "current_time_not_null", Query: "SELECT current_time IS NOT NULL"},
151 {Name: "current_timestamp_not_null", Query: "SELECT current_timestamp IS NOT NULL"},
152 {Name: "now_not_null", Query: "SELECT now() IS NOT NULL"},
153
154 // Extract
155 {Name: "extract_year", Query: "SELECT extract(year from DATE '2024-06-15')"},
156 {Name: "extract_month", Query: "SELECT extract(month from DATE '2024-06-15')"},
157 {Name: "extract_day", Query: "SELECT extract(day from DATE '2024-06-15')"},
158 {Name: "extract_hour", Query: "SELECT extract(hour from TIMESTAMP '2024-06-15 14:30:45')"},
159 {Name: "extract_minute", Query: "SELECT extract(minute from TIMESTAMP '2024-06-15 14:30:45')"},
160 {Name: "extract_second", Query: "SELECT extract(second from TIMESTAMP '2024-06-15 14:30:45')"},
161 {Name: "extract_dow", Query: "SELECT extract(dow from DATE '2024-06-15')"},
162 {Name: "extract_doy", Query: "SELECT extract(doy from DATE '2024-06-15')"},
163 {Name: "extract_week", Query: "SELECT extract(week from DATE '2024-06-15')"},
164 {Name: "extract_quarter", Query: "SELECT extract(quarter from DATE '2024-06-15')"},
165 {Name: "extract_epoch", Query: "SELECT extract(epoch from TIMESTAMP '2024-01-01 00:00:00')"},
166
167 // Date part
168 {Name: "date_part_year", Query: "SELECT date_part('year', DATE '2024-06-15')"},
169 {Name: "date_part_month", Query: "SELECT date_part('month', DATE '2024-06-15')"},
170
171 // Date trunc
172 {Name: "date_trunc_year", Query: "SELECT date_trunc('year', TIMESTAMP '2024-06-15 14:30:45')"},
173 {Name: "date_trunc_month", Query: "SELECT date_trunc('month', TIMESTAMP '2024-06-15 14:30:45')"},
174 {Name: "date_trunc_day", Query: "SELECT date_trunc('day', TIMESTAMP '2024-06-15 14:30:45')"},
175 {Name: "date_trunc_hour", Query: "SELECT date_trunc('hour', TIMESTAMP '2024-06-15 14:30:45')"},
176
177 // Age
178 {Name: "age_two_args", Query: "SELECT age(TIMESTAMP '2024-06-15', TIMESTAMP '2020-01-01')"},
179
180 // Formatting
181 {Name: "to_char_date", Query: "SELECT to_char(DATE '2024-06-15', 'YYYY-MM-DD')"},
182 {Name: "to_char_day_name", Query: "SELECT to_char(DATE '2024-06-15', 'Day')"},
183 {Name: "to_char_number", Query: "SELECT to_char(1234.56, '9999.99')"},
184 {Name: "to_date", Query: "SELECT to_date('2024-06-15', 'YYYY-MM-DD')"},
185 {Name: "to_timestamp", Query: "SELECT to_timestamp('2024-06-15 14:30:45', 'YYYY-MM-DD HH24:MI:SS')"},
186
187 // Make functions
188 {Name: "make_date", Query: "SELECT make_date(2024, 6, 15)"},
189 {Name: "make_time", Query: "SELECT make_time(14, 30, 45)"},
190 {Name: "make_timestamp", Query: "SELECT make_timestamp(2024, 6, 15, 14, 30, 45)"},
191
192 // Misc
193 {Name: "isfinite_date", Query: "SELECT isfinite(DATE '2024-06-15')"},
194 }
195 runQueryTests(t, tests)
196}
197
198// TestFunctionsAggregate tests aggregate functions
199func TestFunctionsAggregate(t *testing.T) {

Callers

nothing calls this directly

Calls 1

runQueryTestsFunction · 0.85

Tested by

no test coverage detected