Skip to content

Commit d555b1d

Browse files
committed
test: forgot date type
Signed-off-by: Dennis Zhuang <[email protected]>
1 parent 2c330fc commit d555b1d

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
-- Migrated from DuckDB test: test/sql/types/date/test_date.test
2+
-- Test basic DATE functionality
3+
-- Create and insert into table
4+
CREATE TABLE dates(i DATE, ts TIMESTAMP TIME INDEX);
5+
6+
Affected Rows: 0
7+
8+
INSERT INTO dates VALUES ('1993-08-14', 1000), (NULL, 2000);
9+
10+
Affected Rows: 2
11+
12+
-- Check that we can select dates
13+
SELECT * FROM dates ORDER BY ts;
14+
15+
+------------+---------------------+
16+
| i | ts |
17+
+------------+---------------------+
18+
| 1993-08-14 | 1970-01-01T00:00:01 |
19+
| | 1970-01-01T00:00:02 |
20+
+------------+---------------------+
21+
22+
-- extract function
23+
SELECT extract(year FROM i) FROM dates ORDER BY ts;
24+
25+
+---------------------------------+
26+
| date_part(Utf8("YEAR"),dates.i) |
27+
+---------------------------------+
28+
| 1993 |
29+
| |
30+
+---------------------------------+
31+
32+
-- Check that we can convert dates to string
33+
SELECT CAST(i AS VARCHAR) FROM dates ORDER BY ts;
34+
35+
+------------+
36+
| dates.i |
37+
+------------+
38+
| 1993-08-14 |
39+
| |
40+
+------------+
41+
42+
-- Check that we can add days to a date
43+
SELECT i + INTERVAL '5 days' FROM dates ORDER BY ts;
44+
45+
+-----------------------------------------------------------------------------------------------+
46+
| dates.i + IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 5, nanoseconds: 0 }") |
47+
+-----------------------------------------------------------------------------------------------+
48+
| 1993-08-19 |
49+
| |
50+
+-----------------------------------------------------------------------------------------------+
51+
52+
-- Check that we can subtract days from a date
53+
SELECT i - INTERVAL '5 days' FROM dates ORDER BY ts;
54+
55+
+-----------------------------------------------------------------------------------------------+
56+
| dates.i - IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 5, nanoseconds: 0 }") |
57+
+-----------------------------------------------------------------------------------------------+
58+
| 1993-08-09 |
59+
| |
60+
+-----------------------------------------------------------------------------------------------+
61+
62+
-- Test date subtraction resulting in interval
63+
SELECT i - DATE '1993-08-14' FROM dates ORDER BY ts;
64+
65+
+------------------------------+
66+
| dates.i - Utf8("1993-08-14") |
67+
+------------------------------+
68+
| P0D |
69+
| |
70+
+------------------------------+
71+
72+
-- Test various date formats
73+
CREATE TABLE date_formats(d DATE, ts TIMESTAMP TIME INDEX);
74+
75+
Affected Rows: 0
76+
77+
INSERT INTO date_formats VALUES
78+
('2021-03-01', 1000),
79+
('2021-12-31', 2000),
80+
('2000-01-01', 3000),
81+
('1970-01-01', 4000);
82+
83+
Affected Rows: 4
84+
85+
SELECT d, extract(year FROM d), extract(month FROM d), extract(day FROM d) FROM date_formats ORDER BY d;
86+
87+
+------------+----------------------------------------+-----------------------------------------+---------------------------------------+
88+
| d | date_part(Utf8("YEAR"),date_formats.d) | date_part(Utf8("MONTH"),date_formats.d) | date_part(Utf8("DAY"),date_formats.d) |
89+
+------------+----------------------------------------+-----------------------------------------+---------------------------------------+
90+
| 1970-01-01 | 1970 | 1 | 1 |
91+
| 2000-01-01 | 2000 | 1 | 1 |
92+
| 2021-03-01 | 2021 | 3 | 1 |
93+
| 2021-12-31 | 2021 | 12 | 31 |
94+
+------------+----------------------------------------+-----------------------------------------+---------------------------------------+
95+
96+
-- Test date comparison
97+
SELECT d FROM date_formats WHERE d > '2000-01-01' ORDER BY d;
98+
99+
+------------+
100+
| d |
101+
+------------+
102+
| 2021-03-01 |
103+
| 2021-12-31 |
104+
+------------+
105+
106+
SELECT d FROM date_formats WHERE d BETWEEN '2000-01-01' AND '2021-06-01' ORDER BY d;
107+
108+
+------------+
109+
| d |
110+
+------------+
111+
| 2000-01-01 |
112+
| 2021-03-01 |
113+
+------------+
114+
115+
-- Test NULL handling
116+
INSERT INTO date_formats VALUES (NULL, 5000);
117+
118+
Affected Rows: 1
119+
120+
SELECT COUNT(*), COUNT(d) FROM date_formats;
121+
122+
+----------+-----------------------+
123+
| count(*) | count(date_formats.d) |
124+
+----------+-----------------------+
125+
| 5 | 4 |
126+
+----------+-----------------------+
127+
128+
DROP TABLE dates;
129+
130+
Affected Rows: 0
131+
132+
DROP TABLE date_formats;
133+
134+
Affected Rows: 0
135+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Migrated from DuckDB test: test/sql/types/date/test_date.test
2+
-- Test basic DATE functionality
3+
4+
-- Create and insert into table
5+
CREATE TABLE dates(i DATE, ts TIMESTAMP TIME INDEX);
6+
7+
INSERT INTO dates VALUES ('1993-08-14', 1000), (NULL, 2000);
8+
9+
-- Check that we can select dates
10+
SELECT * FROM dates ORDER BY ts;
11+
12+
-- extract function
13+
SELECT extract(year FROM i) FROM dates ORDER BY ts;
14+
15+
-- Check that we can convert dates to string
16+
SELECT CAST(i AS VARCHAR) FROM dates ORDER BY ts;
17+
18+
-- Check that we can add days to a date
19+
SELECT i + INTERVAL '5 days' FROM dates ORDER BY ts;
20+
21+
-- Check that we can subtract days from a date
22+
SELECT i - INTERVAL '5 days' FROM dates ORDER BY ts;
23+
24+
-- Test date subtraction resulting in interval
25+
SELECT i - DATE '1993-08-14' FROM dates ORDER BY ts;
26+
27+
-- Test various date formats
28+
CREATE TABLE date_formats(d DATE, ts TIMESTAMP TIME INDEX);
29+
30+
INSERT INTO date_formats VALUES
31+
('2021-03-01', 1000),
32+
('2021-12-31', 2000),
33+
('2000-01-01', 3000),
34+
('1970-01-01', 4000);
35+
36+
SELECT d, extract(year FROM d), extract(month FROM d), extract(day FROM d) FROM date_formats ORDER BY d;
37+
38+
-- Test date comparison
39+
SELECT d FROM date_formats WHERE d > '2000-01-01' ORDER BY d;
40+
41+
SELECT d FROM date_formats WHERE d BETWEEN '2000-01-01' AND '2021-06-01' ORDER BY d;
42+
43+
-- Test NULL handling
44+
INSERT INTO date_formats VALUES (NULL, 5000);
45+
46+
SELECT COUNT(*), COUNT(d) FROM date_formats;
47+
48+
DROP TABLE dates;
49+
50+
DROP TABLE date_formats;

0 commit comments

Comments
 (0)