~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# time functions
3
#
4
--disable_warnings
5
drop table if exists t1,t2,t3;
6
--enable_warnings
7
8
select from_days(to_days("960101")),to_days(960201)-to_days("19960101"),to_days(date_add(curdate(), interval 1 day))-to_days(curdate()),weekday("1997-11-29");
9
select period_add("9602",-12),period_diff(199505,"9404") ;
10
11
select now()-now(),weekday(curdate())-weekday(now()),unix_timestamp()-unix_timestamp(now());
12
select from_unixtime(unix_timestamp("1994-03-02 10:11:12")),from_unixtime(unix_timestamp("1994-03-02 10:11:12"),"%Y-%m-%d %h:%i:%s"),from_unixtime(unix_timestamp("1994-03-02 10:11:12"))+0;
13
select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"),
14
  sec_to_time(time_to_sec("0:30:47")/6.21);
15
select sec_to_time(time_to_sec('-838:59:59'));
16
select now()-curdate()*1000000-curtime();
17
select strcmp(current_timestamp(),concat(current_date()," ",current_time()));
18
select strcmp(localtime(),concat(current_date()," ",current_time()));
19
select strcmp(localtimestamp(),concat(current_date()," ",current_time()));
20
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w");
21
select date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w"));
22
select dayofmonth("1997-01-02"),dayofmonth(19970323);
23
select month("1997-01-02"),year("98-02-03"),dayofyear("1997-12-31");
813.1.9 by Jay Pipes
Fixes to existing func_time.test for bad datetimes passed to MONTH() and MONTHNAME() function.
24
--error 1686 # No more bad dates!
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
25
select month("2001-02-00"),year("2001-01-01");
1 by brian
clean slate
26
select DAYOFYEAR("1997-03-03"), WEEK("1998-03-03"), QUARTER(980303);
27
select HOUR("1997-03-03 23:03:22"), MINUTE("23:03:22"), SECOND(230322);
28
29
# Test of week and yearweek
30
select week(19980101),week(19970101),week(19980101,1),week(19970101,1);
31
select week(19981231),week(19971231),week(19981231,1),week(19971231,1);
32
select week(19950101),week(19950101,1);
33
select yearweek('1981-12-31',1),yearweek('1982-01-01',1),yearweek('1982-12-31',1),yearweek('1983-01-01',1);
34
select yearweek('1987-01-01',1),yearweek('1987-01-01');
35
select week("2000-01-01",0) as '2000', week("2001-01-01",0) as '2001', week("2002-01-01",0) as '2002',week("2003-01-01",0) as '2003', week("2004-01-01",0) as '2004', week("2005-01-01",0) as '2005', week("2006-01-01",0) as '2006';
36
select week("2000-01-06",0) as '2000', week("2001-01-06",0) as '2001', week("2002-01-06",0) as '2002',week("2003-01-06",0) as '2003', week("2004-01-06",0) as '2004', week("2005-01-06",0) as '2005', week("2006-01-06",0) as '2006';
37
select week("2000-01-01",1) as '2000', week("2001-01-01",1) as '2001', week("2002-01-01",1) as '2002',week("2003-01-01",1) as '2003', week("2004-01-01",1) as '2004', week("2005-01-01",1) as '2005', week("2006-01-01",1) as '2006';
38
select week("2000-01-06",1) as '2000', week("2001-01-06",1) as '2001', week("2002-01-06",1) as '2002',week("2003-01-06",1) as '2003', week("2004-01-06",1) as '2004', week("2005-01-06",1) as '2005', week("2006-01-06",1) as '2006';
39
select yearweek("2000-01-01",0) as '2000', yearweek("2001-01-01",0) as '2001', yearweek("2002-01-01",0) as '2002',yearweek("2003-01-01",0) as '2003', yearweek("2004-01-01",0) as '2004', yearweek("2005-01-01",0) as '2005', yearweek("2006-01-01",0) as '2006';
40
select yearweek("2000-01-06",0) as '2000', yearweek("2001-01-06",0) as '2001', yearweek("2002-01-06",0) as '2002',yearweek("2003-01-06",0) as '2003', yearweek("2004-01-06",0) as '2004', yearweek("2005-01-06",0) as '2005', yearweek("2006-01-06",0) as '2006';
41
select yearweek("2000-01-01",1) as '2000', yearweek("2001-01-01",1) as '2001', yearweek("2002-01-01",1) as '2002',yearweek("2003-01-01",1) as '2003', yearweek("2004-01-01",1) as '2004', yearweek("2005-01-01",1) as '2005', yearweek("2006-01-01",1) as '2006';
42
select yearweek("2000-01-06",1) as '2000', yearweek("2001-01-06",1) as '2001', yearweek("2002-01-06",1) as '2002',yearweek("2003-01-06",1) as '2003', yearweek("2004-01-06",1) as '2004', yearweek("2005-01-06",1) as '2005', yearweek("2006-01-06",1) as '2006';
43
select week(19981231,2), week(19981231,3), week(20000101,2), week(20000101,3);
44
select week(20001231,2),week(20001231,3);
45
46
select week(19981231,0) as '0', week(19981231,1) as '1', week(19981231,2) as '2', week(19981231,3) as '3', week(19981231,4) as '4', week(19981231,5) as '5', week(19981231,6) as '6', week(19981231,7) as '7';
47
select week(20000101,0) as '0', week(20000101,1) as '1', week(20000101,2) as '2', week(20000101,3) as '3', week(20000101,4) as '4', week(20000101,5) as '5', week(20000101,6) as '6', week(20000101,7) as '7';
48
select week(20000106,0) as '0', week(20000106,1) as '1', week(20000106,2) as '2', week(20000106,3) as '3', week(20000106,4) as '4', week(20000106,5) as '5', week(20000106,6) as '6', week(20000106,7) as '7';
49
select week(20001231,0) as '0', week(20001231,1) as '1', week(20001231,2) as '2', week(20001231,3) as '3', week(20001231,4) as '4', week(20001231,5) as '5', week(20001231,6) as '6', week(20001231,7) as '7';
50
select week(20010101,0) as '0', week(20010101,1) as '1', week(20010101,2) as '2', week(20010101,3) as '3', week(20010101,4) as '4', week(20010101,5) as '5', week(20010101,6) as '6', week(20010101,7) as '7';
51
52
select yearweek(20001231,0), yearweek(20001231,1), yearweek(20001231,2), yearweek(20001231,3), yearweek(20001231,4), yearweek(20001231,5), yearweek(20001231,6), yearweek(20001231,7);
53
54
set default_week_format = 6;
55
select week(20001231), week(20001231,6);
56
set default_week_format = 0;
57
58
set default_week_format = 2;
59
select week(20001231),week(20001231,2),week(20001231,0);
60
set default_week_format = 0;
61
62
select date_format('1998-12-31','%x-%v'),date_format('1999-01-01','%x-%v');
63
select date_format('1999-12-31','%x-%v'),date_format('2000-01-01','%x-%v');
64
65
select dayname("1962-03-03"),dayname("1962-03-03")+0;
66
select monthname("1972-03-04"),monthname("1972-03-04")+0;
67
select time_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
68
select time_format(19980131010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
69
select time_format(19980131131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
70
select time_format(19980131010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
71
select date_format(concat('19980131',131415),'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w');
72
select date_format(19980021000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w');
73
select date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND);
74
select date_add("1997-12-31 23:59:59",INTERVAL 1 MINUTE);
75
select date_add("1997-12-31 23:59:59",INTERVAL 1 HOUR);
76
select date_add("1997-12-31 23:59:59",INTERVAL 1 DAY);
77
select date_add("1997-12-31 23:59:59",INTERVAL 1 MONTH);
78
select date_add("1997-12-31 23:59:59",INTERVAL 1 YEAR);
79
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND);
80
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" HOUR_MINUTE);
81
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" DAY_HOUR);
82
select date_add("1997-12-31 23:59:59",INTERVAL "1 1" YEAR_MONTH);
83
select date_add("1997-12-31 23:59:59",INTERVAL "1:1:1" HOUR_SECOND);
84
select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1" DAY_MINUTE);
85
select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1:1" DAY_SECOND);
86
87
select date_sub("1998-01-01 00:00:00",INTERVAL 1 SECOND);
88
select date_sub("1998-01-01 00:00:00",INTERVAL 1 MINUTE);
89
select date_sub("1998-01-01 00:00:00",INTERVAL 1 HOUR);
90
select date_sub("1998-01-01 00:00:00",INTERVAL 1 DAY);
91
select date_sub("1998-01-01 00:00:00",INTERVAL 1 MONTH);
92
select date_sub("1998-01-01 00:00:00",INTERVAL 1 YEAR);
93
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" MINUTE_SECOND);
94
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" HOUR_MINUTE);
95
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" DAY_HOUR);
96
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1" YEAR_MONTH);
97
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1:1" HOUR_SECOND);
98
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1" DAY_MINUTE);
99
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND);
100
101
select date_add("1997-12-31 23:59:59",INTERVAL 100000 SECOND);
102
select date_add("1997-12-31 23:59:59",INTERVAL -100000 MINUTE);
103
select date_add("1997-12-31 23:59:59",INTERVAL 100000 HOUR);
104
select date_add("1997-12-31 23:59:59",INTERVAL -100000 DAY);
105
select date_add("1997-12-31 23:59:59",INTERVAL 100000 MONTH);
106
select date_add("1997-12-31 23:59:59",INTERVAL -100000 YEAR);
107
select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" MINUTE_SECOND);
108
select date_add("1997-12-31 23:59:59",INTERVAL "-10000:1" HOUR_MINUTE);
109
select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" DAY_HOUR);
110
select date_add("1997-12-31 23:59:59",INTERVAL "-100 1" YEAR_MONTH);
111
select date_add("1997-12-31 23:59:59",INTERVAL "10000:99:99" HOUR_SECOND);
112
select date_add("1997-12-31 23:59:59",INTERVAL " -10000 99:99" DAY_MINUTE);
113
select date_add("1997-12-31 23:59:59",INTERVAL "10000 99:99:99" DAY_SECOND);
114
select "1997-12-31 23:59:59" + INTERVAL 1 SECOND;
115
select INTERVAL 1 DAY + "1997-12-31";
116
select "1998-01-01 00:00:00" - INTERVAL 1 SECOND;
117
118
select date_sub("1998-01-02",INTERVAL 31 DAY);
119
select date_add("1997-12-31",INTERVAL 1 SECOND);
120
select date_add("1997-12-31",INTERVAL 1 DAY);
121
select date_add(NULL,INTERVAL 100000 SECOND);
122
select date_add("1997-12-31 23:59:59",INTERVAL NULL SECOND);
123
select date_add("1997-12-31 23:59:59",INTERVAL NULL MINUTE_SECOND);
124
select date_add("9999-12-31 23:59:59",INTERVAL 1 SECOND);
125
select date_sub("0000-00-00 00:00:00",INTERVAL 1 SECOND);
126
select date_add('1998-01-30',Interval 1 month);
127
select date_add('1998-01-30',Interval '2:1' year_month);
128
select date_add('1996-02-29',Interval '1' year);
129
select extract(YEAR FROM "1999-01-02 10:11:12");
130
select extract(YEAR_MONTH FROM "1999-01-02");
131
select extract(DAY FROM "1999-01-02");
132
select extract(DAY_HOUR FROM "1999-01-02 10:11:12");
133
select extract(DAY_MINUTE FROM "02 10:11:12");
134
select extract(DAY_SECOND FROM "225 10:11:12");
135
select extract(HOUR FROM "1999-01-02 10:11:12");
136
select extract(HOUR_MINUTE FROM "10:11:12");
137
select extract(HOUR_SECOND FROM "10:11:12");
138
select extract(MINUTE FROM "10:11:12");
139
select extract(MINUTE_SECOND FROM "10:11:12");
140
select extract(SECOND FROM "1999-01-02 10:11:12");
141
select extract(MONTH FROM "2001-02-00");
142
143
#
144
# test EXTRACT QUARTER (Bug #18100)
145
#
146
147
SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter;
148
SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter;
149
SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter;
150
SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter;
151
SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter;
152
SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter;
153
SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter;
154
SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter;
155
SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter;
156
SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter;
157
SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter;
158
SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter;
159
#
160
# MySQL Bugs: #12356: DATE_SUB or DATE_ADD incorrectly returns null
161
#
162
SELECT DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
163
SELECT DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
164
165
#
166
# Test big intervals (Bug #3498)
167
#
168
SELECT "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND;
169
SELECT "1900-01-01 00:00:00" + INTERVAL "1:2147483647" MINUTE_SECOND;
506 by Brian Aker
Added back more tests.
170
SELECT "1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND;
1 by brian
clean slate
171
SELECT "1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND;
172
173
#
174
# Bug #614 (multiple extracts in where)
175
#
176
177
create table t1 (ctime varchar(20));
178
insert into t1 values ('2001-01-12 12:23:40');
179
select ctime, hour(ctime) from t1;
180
select ctime from t1 where extract(MONTH FROM ctime) = 1 AND extract(YEAR FROM ctime) = 2001;
181
drop table t1;
182
183
#
184
# Test bug with monthname() and NULL
185
#
186
187
create table t1 (id int);
188
create table t2 (id int, date date);
189
insert into t1 values (1);
813.1.9 by Jay Pipes
Fixes to existing func_time.test for bad datetimes passed to MONTH() and MONTHNAME() function.
190
insert into t2 values (1, NULL);
1 by brian
clean slate
191
insert into t1 values (2);
192
insert into t2 values (2, "2000-01-01");
193
select monthname(date) from t1 inner join t2 on t1.id = t2.id;
194
select monthname(date) from t1 inner join t2 on t1.id = t2.id order by t1.id;
195
drop table t1,t2;
196
197
#
198
# Test bug with month() and year() on text fields with wrong information
199
200
CREATE TABLE t1 (updated text) ENGINE=MyISAM;
201
INSERT INTO t1 VALUES ('');
813.1.9 by Jay Pipes
Fixes to existing func_time.test for bad datetimes passed to MONTH() and MONTHNAME() function.
202
--error 1686 # "" is not a date!
1 by brian
clean slate
203
SELECT month(updated) from t1;
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
204
--error 1686 # "" is not a date for pete's sake.
1 by brian
clean slate
205
SELECT year(updated) from t1;
206
drop table t1;
207
208
#
209
# Check that functions work identically on 0000-00-00 as a constant and on a
210
# column
211
#
212
213
create table t1 (d date, dt datetime, t timestamp, c char(10));
214
insert into t1 values ("0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");
813.1.11 by Jay Pipes
Fixed DAYOFYEAR() to use new Temporal system, corrected func_time.test
215
--error 1686 # 0000-00-00 is a bad date
1 by brian
clean slate
216
select dayofyear("0000-00-00"),dayofyear(d),dayofyear(dt),dayofyear(t),dayofyear(c) from t1;
813.1.10 by Jay Pipes
Fixes DAYOFMONTH() function to use new Temporal system. Now throws
217
--error 1686 # 0000-00-00 is a bad date
1 by brian
clean slate
218
select dayofmonth("0000-00-00"),dayofmonth(d),dayofmonth(dt),dayofmonth(t),dayofmonth(c) from t1;
813.1.9 by Jay Pipes
Fixes to existing func_time.test for bad datetimes passed to MONTH() and MONTHNAME() function.
219
--error 1686 # 0000-00-00 is not a damn date.
1 by brian
clean slate
220
select month("0000-00-00"),month(d),month(dt),month(t),month(c) from t1;
813.1.20 by Jay Pipes
Fixes for the QUARTER() function to use new Temporal system and throw
221
--error 1686 # 0000-00-00 not a date
1 by brian
clean slate
222
select quarter("0000-00-00"),quarter(d),quarter(dt),quarter(t),quarter(c) from t1;
223
select week("0000-00-00"),week(d),week(dt),week(t),week(c) from t1;
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
224
--error 1686 # Argh.  0000-00-00 is not a date.
1 by brian
clean slate
225
select year("0000-00-00"),year(d),year(dt),year(t),year(c) from t1;
226
select yearweek("0000-00-00"),yearweek(d),yearweek(dt),yearweek(t),yearweek(c) from t1;
227
select to_days("0000-00-00"),to_days(d),to_days(dt),to_days(t),to_days(c) from t1;
228
select extract(MONTH FROM "0000-00-00"),extract(MONTH FROM d),extract(MONTH FROM dt),extract(MONTH FROM t),extract(MONTH FROM c) from t1;
229
drop table t1;
230
231
232
#
233
# Test problem with TIMESTAMP and BETWEEN
234
#
235
236
CREATE TABLE t1 ( start datetime default NULL);
237
INSERT INTO t1 VALUES ('2002-10-21 00:00:00'),('2002-10-28 00:00:00'),('2002-11-04 00:00:00');
238
CREATE TABLE t2 ( ctime1 timestamp NOT NULL, ctime2 timestamp NOT NULL);
239
INSERT INTO t2 VALUES (20021029165106,20021105164731);
240
CREATE TABLE t3 (ctime1 char(19) NOT NULL, ctime2 char(19) NOT NULL);
241
INSERT INTO t3 VALUES ("2002-10-29 16:51:06","2002-11-05 16:47:31");
242
243
# The following statement should be fixed to return a row in 4.1
244
select * from t1, t2 where t1.start between t2.ctime1 and t2.ctime2;
245
select * from t1, t2 where t1.start >= t2.ctime1 and t1.start <= t2.ctime2;
246
select * from t1, t3 where t1.start between t3.ctime1 and t3.ctime2;
247
drop table t1,t2,t3;
248
249
#
250
# Test unix timestamp
251
#
252
select @a:=FROM_UNIXTIME(1);
253
select unix_timestamp(@a);
254
select unix_timestamp('1969-12-01 19:00:01');
255
256
#
257
# Tests for bug #6439 "unix_timestamp() function returns wrong datetime 
258
# values for too big argument", bug #7515 "from_unixtime(0) now
259
# returns NULL instead of the epoch" and bug #9191
260
# "TIMESTAMP/from_unixtime() no longer accepts 2^31-1."
261
# unix_timestamp() should return error for too big or negative argument.
262
# It should return Epoch value for zero argument since it seems that many
263
# users rely on this fact, from_unixtime() should work with values
264
# up to INT_MAX32 because of the same reason.
265
#
266
select from_unixtime(-1);
267
# check for from_unixtime(2^31-1) and from_unixtime(2^31)
268
select from_unixtime(2147483647);
269
select from_unixtime(2147483648);
270
select from_unixtime(0);
271
272
#
273
# Some more tests for bug #9191 "TIMESTAMP/from_unixtime() no
274
# longer accepts 2^31-1". Here we test that from_unixtime and
275
# unix_timestamp are consistent, when working with boundary dates.
276
#
277
select unix_timestamp(from_unixtime(2147483647));
278
select unix_timestamp(from_unixtime(2147483648));
279
280
# check for invalid dates
281
282
# bad year
283
select unix_timestamp('2039-01-20 01:00:00');
284
select unix_timestamp('1968-01-20 01:00:00');
285
# bad month
286
select unix_timestamp('2038-02-10 01:00:00');
287
select unix_timestamp('1969-11-20 01:00:00');
288
# bad day
289
select unix_timestamp('2038-01-20 01:00:00');
290
select unix_timestamp('1969-12-30 01:00:00');
291
292
#
293
# Check negative shift (we subtract several days for boundary dates during
294
# conversion).
295
select unix_timestamp('2038-01-17 12:00:00');
296
297
#
298
# Check positive shift. (it happens only on
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
299
# platfroms with time_t, such as QNX)
1 by brian
clean slate
300
#
301
select unix_timestamp('1970-01-01 03:00:01');
302
303
# check bad date, close to the boundary (we cut them off in the very end)
304
select unix_timestamp('2038-01-19 07:14:07');
305
306
307
#
308
# Test types from + INTERVAL
309
#
310
311
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date, time time);
312
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02", "06:07:08");
313
SELECT * from t1;
314
select date_add("1997-12-31",INTERVAL 1 SECOND);
315
select date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH);
316
317
select date_add(datetime, INTERVAL 1 SECOND) from t1;
318
select date_add(datetime, INTERVAL 1 YEAR) from t1;
319
320
select date_add(date,INTERVAL 1 SECOND) from t1;
321
select date_add(date,INTERVAL 1 MINUTE) from t1;
322
select date_add(date,INTERVAL 1 HOUR) from t1;
323
select date_add(date,INTERVAL 1 DAY) from t1;
324
select date_add(date,INTERVAL 1 MONTH) from t1;
325
select date_add(date,INTERVAL 1 YEAR) from t1;
326
select date_add(date,INTERVAL "1:1" MINUTE_SECOND) from t1;
327
select date_add(date,INTERVAL "1:1" HOUR_MINUTE) from t1;
328
select date_add(date,INTERVAL "1:1" DAY_HOUR) from t1;
329
select date_add(date,INTERVAL "1 1" YEAR_MONTH) from t1;
330
select date_add(date,INTERVAL "1:1:1" HOUR_SECOND) from t1;
331
select date_add(date,INTERVAL "1 1:1" DAY_MINUTE) from t1;
332
select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
333
select date_add(date,INTERVAL "1" WEEK) from t1;
334
select date_add(date,INTERVAL "1" QUARTER) from t1;
335
select timestampadd(MINUTE, 1, date) from t1;
336
select timestampadd(WEEK, 1, date) from t1;
337
select timestampadd(SQL_TSI_SECOND, 1, date) from t1;
338
# mysqltest.c discards an expected 'deprecated' warning on prepare stage
339
--disable_ps_protocol
340
select timestampadd(SQL_TSI_FRAC_SECOND, 1, date) from t1;
341
--enable_ps_protocol
342
343
select timestampdiff(MONTH, '2001-02-01', '2001-05-01') as a;
344
select timestampdiff(YEAR, '2002-05-01', '2001-01-01') as a;
345
select timestampdiff(QUARTER, '2002-05-01', '2001-01-01') as a;
346
select timestampdiff(MONTH, '2000-03-28', '2000-02-29') as a;
347
select timestampdiff(MONTH, '1991-03-28', '2000-02-29') as a;
348
select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a;
349
select timestampdiff(SQL_TSI_HOUR, '2001-02-01', '2001-05-01') as a;
350
select timestampdiff(SQL_TSI_DAY, '2001-02-01', '2001-05-01') as a;
351
select timestampdiff(SQL_TSI_MINUTE, '2001-02-01 12:59:59', '2001-05-01 12:58:59') as a;
352
select timestampdiff(SQL_TSI_SECOND, '2001-02-01 12:59:59', '2001-05-01 12:58:58') as a;
353
# mysqltest.c discards an expected 'deprecated' warning on prepare stage
354
--disable_ps_protocol
355
select timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a;
356
--enable_ps_protocol
357
358
select timestampdiff(SQL_TSI_DAY, '1986-02-01', '1986-03-01') as a1,
359
       timestampdiff(SQL_TSI_DAY, '1900-02-01', '1900-03-01') as a2,
360
       timestampdiff(SQL_TSI_DAY, '1996-02-01', '1996-03-01') as a3,
361
       timestampdiff(SQL_TSI_DAY, '2000-02-01', '2000-03-01') as a4;
362
363
# bug 16226
364
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27');
365
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28');
366
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29');
367
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27');
368
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28');
369
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29');
370
371
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27');
372
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28');
373
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29');
374
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27');
375
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28');
376
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29');
377
378
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27');
379
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28');
380
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29');
381
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27');
382
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28');
383
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29');
384
385
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27');
386
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28');
387
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29');
388
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27');
389
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28');
390
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29');
391
392
# end of bug
393
394
select date_add(time,INTERVAL 1 SECOND) from t1;
395
drop table t1;
396
397
# test for last_day
398
select last_day('2000-02-05') as f1, last_day('2002-12-31') as f2,
399
       last_day('2003-03-32') as f3, last_day('2003-04-01') as f4,
400
       last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
401
       last_day('2001-02-12');
402
403
create table t1 select last_day('2000-02-05') as a,
404
                from_days(to_days("960101")) as b;
405
describe t1;
406
select * from t1;
407
drop table t1;
408
select last_day('2000-02-05') as a,
409
       from_days(to_days("960101")) as b;
410
411
select date_add(last_day("1997-12-1"), INTERVAL 1 DAY);
412
select length(last_day("1997-12-1"));
413
select last_day("1997-12-1")+0;
414
select last_day("1997-12-1")+0.0;
415
416
# Test SAPDB UTC_% functions. This part is TZ dependant (It is supposed that
417
# TZ variable set to GMT-3
418
419
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
420
select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%T"), utc_time())=0;
421
select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d"), utc_date())=0;
422
select strcmp(date_format(utc_timestamp(),"%T"), utc_time())=0;
423
select strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0;
424
select strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0;
425
426
explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_days(to_days("960101")),dayofmonth("1997-01-02"), month("1997-01-02"), monthname("1972-03-04"),dayofyear("0000-00-00"),HOUR("1997-03-03 23:03:22"),MINUTE("23:03:22"),SECOND(230322),QUARTER(980303),WEEK("1998-03-03"),yearweek("2000-01-01",1),week(19950101,1),year("98-02-03"),weekday(curdate())-weekday(now()),dayname("1962-03-03"),unix_timestamp(),sec_to_time(time_to_sec("0:30:47")/6.21),curtime(),utc_time(),curdate(),utc_date(),utc_timestamp(),date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w"),from_unixtime(unix_timestamp("1994-03-02 10:11:12")),"1997-12-31 23:59:59" + INTERVAL 1 SECOND,"1998-01-01 00:00:00" - INTERVAL 1 SECOND,INTERVAL 1 DAY + "1997-12-31", extract(YEAR FROM "1999-01-02 10:11:12"),date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND);
427
428
SET @TMP='2007-08-01 12:22:49';
429
CREATE TABLE t1 (d DATETIME);
430
INSERT INTO t1 VALUES ('2007-08-01 12:22:59');
431
INSERT INTO t1 VALUES ('2007-08-01 12:23:01');
432
INSERT INTO t1 VALUES ('2007-08-01 12:23:20');
433
SELECT count(*) FROM t1 WHERE d>FROM_DAYS(TO_DAYS(@TMP)) AND d<=FROM_DAYS(TO_DAYS(@TMP)+1);
434
DROP TABLE t1;
435
436
#
437
# Bug #10568
438
#
439
440
select last_day('2005-00-00');
441
select last_day('2005-00-01');
442
select last_day('2005-01-00');
443
444
#
445
# Bug #18501: monthname and NULLs
446
#
447
813.1.9 by Jay Pipes
Fixes to existing func_time.test for bad datetimes passed to MONTH() and MONTHNAME() function.
448
--error 1686 # Once again no bad dates allowed!
1 by brian
clean slate
449
select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
450
       monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));
451
452
#
453
# Bug#16377 result of DATE/TIME functions were compared as strings which
454
#           can lead to a wrong result.
455
# Now wrong dates should be compared only with CAST()
456
create table t1(f1 date, f2 time, f3 datetime);
457
insert into t1 values ("2006-01-01", "12:01:01", "2006-01-01 12:01:01");
458
insert into t1 values ("2006-01-02", "12:01:02", "2006-01-02 12:01:02");
459
select f1 from t1 where f1 between CAST("2006-1-1" as date) and CAST(20060101 as date);
460
select f1 from t1 where f1 between cast("2006-1-1" as date) and cast("2006.1.1" as date);
461
select f1 from t1 where date(f1) between cast("2006-1-1" as date) and cast("2006.1.1" as date);
462
select f2 from t1 where f2 between cast("12:1:2" as time) and cast("12:2:2" as time);
463
select f2 from t1 where time(f2) between cast("12:1:2" as time) and cast("12:2:2" as time);
464
select f3 from t1 where f3 between cast("2006-1-1 12:1:1" as datetime) and cast("2006-1-1 12:1:2" as datetime);
465
select f3 from t1 where timestamp(f3) between cast("2006-1-1 12:1:1" as datetime) and cast("2006-1-1 12:1:2" as datetime);
466
select f1 from t1 where cast("2006-1-1" as date) between f1 and f3;
467
select f1 from t1 where cast("2006-1-1" as date) between date(f1) and date(f3);
468
select f1 from t1 where cast("2006-1-1" as date) between f1 and cast('zzz' as date);
469
select f1 from t1 where makedate(2006,1) between date(f1) and date(f3);
470
select f1 from t1 where makedate(2006,2) between date(f1) and date(f3);
471
drop table t1;
472
473
#
474
# Bug #16546
475
# 
476
477
create table t1 select now() - now(), curtime() - curtime(), 
478
                       sec_to_time(1) + 0, from_unixtime(1) + 0;
479
show create table t1;
480
drop table t1;
481
482
#
483
# Bug #11655: Wrong time is returning from nested selects - maximum time exists
484
#
485
# check if SEC_TO_TIME() handles out-of-range values correctly
486
SELECT SEC_TO_TIME(3300000);
487
SELECT SEC_TO_TIME(3300000)+0;
488
SELECT SEC_TO_TIME(3600 * 4294967296);
489
490
# check if TIME_TO_SEC() handles out-of-range values correctly
491
SELECT TIME_TO_SEC('916:40:00');
492
493
# check if ADDTIME() handles out-of-range values correctly
494
SELECT ADDTIME('500:00:00', '416:40:00');
495
SELECT ADDTIME('916:40:00', '416:40:00');
496
497
# check if SUBTIME() handles out-of-range values correctly
498
SELECT SUBTIME('916:40:00', '416:40:00');
499
SELECT SUBTIME('-916:40:00', '416:40:00');
500
501
# check if MAKETIME() handles out-of-range values correctly
502
SELECT MAKETIME(916,0,0);
503
SELECT MAKETIME(4294967296, 0, 0);
504
SELECT MAKETIME(-4294967296, 0, 0);
505
SELECT MAKETIME(0, 4294967296, 0);
506
SELECT MAKETIME(0, 0, 4294967296);
507
508
# check if EXTRACT() handles out-of-range values correctly
509
SELECT EXTRACT(HOUR FROM '100000:02:03');
510
511
# check if we get proper warnings if both input string truncation
512
# and out-of-range value occur
513
CREATE TABLE t1(f1 TIME);
506 by Brian Aker
Added back more tests.
514
--error 1292
1 by brian
clean slate
515
INSERT INTO t1 VALUES('916:00:00 a');
516
SELECT * FROM t1;
517
DROP TABLE t1;
518
519
#
520
# 21913: DATE_FORMAT() Crashes mysql server if I use it through
521
#        mysql-connector-j driver.
522
#
523
524
SHOW VARIABLES LIKE 'character_set_results';
525
506 by Brian Aker
Added back more tests.
526
CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32));
1 by brian
clean slate
527
INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd');
528
529
SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868;
530
531
DROP TABLE testBug8868;
532
533
#
534
# Bug #31160: MAKETIME() crashes server when returning NULL in ORDER BY using 
535
# filesort
536
#
537
CREATE TABLE t1 (
538
  a TIMESTAMP
539
);
540
INSERT INTO t1 VALUES (now()), (now());
541
SELECT 1 FROM t1 ORDER BY MAKETIME(1, 1, a);
542
DROP TABLE t1;
543
#
544
# Bug #19844 time_format in Union truncates values
545
#
546
547
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H)
548
union
549
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H);
550
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%k') As H)
551
union
552
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%k') As H);
553
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%H') As H)
554
union
555
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%H') As H);
556
557
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H)
558
union
559
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H);
560
561
#
562
# Bug #23653: crash if last_day('0000-00-00')
563
#
564
565
select last_day('0000-00-00');
566
567
#
568
# Bug 23616: datetime functions with double argumets
569
#
570
571
select isnull(week(now() + 0)), isnull(week(now() + 0.2)),
572
  week(20061108), week(20061108.01), week(20061108085411.000002);
573
574
--echo End of 4.1 tests
575
576
explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1,
577
			timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2;
578
579
#
580
# Bug #10590: %h, %I, and %l format specifies should all return results in
581
# the 0-11 range
582
#
583
select time_format('100:00:00', '%H %k %h %I %l');
584
585
#
586
# Bug #13534: timestampdiff() returned incorrect results across leap years
587
#
588
select timestampdiff(month,'2004-09-11','2004-09-11');
589
select timestampdiff(month,'2004-09-11','2005-09-11');
590
select timestampdiff(month,'2004-09-11','2006-09-11');
591
select timestampdiff(month,'2004-09-11','2007-09-11');
592
select timestampdiff(month,'2005-09-11','2004-09-11');
593
select timestampdiff(month,'2005-09-11','2003-09-11');
594
595
select timestampdiff(month,'2004-02-28','2005-02-28');
596
select timestampdiff(month,'2004-02-29','2005-02-28');
597
select timestampdiff(month,'2004-02-28','2005-02-28');
598
select timestampdiff(month,'2004-03-29','2005-03-28');
599
select timestampdiff(month,'2003-02-28','2004-02-29');
600
select timestampdiff(month,'2003-02-28','2005-02-28');
601
602
select timestampdiff(month,'1999-09-11','2001-10-10');
603
select timestampdiff(month,'1999-09-11','2001-9-11');
604
605
select timestampdiff(year,'1999-09-11','2001-9-11');
606
select timestampdiff(year,'2004-02-28','2005-02-28');
607
select timestampdiff(year,'2004-02-29','2005-02-28');
608
609
#
610
# Bug #18618: BETWEEN for dates with the second argument being a constant
611
#             expression and the first and the third arguments being fields 
612
#
613
614
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date);
615
CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date);
616
617
INSERT INTO t1 VALUES
618
  (1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01');
619
INSERT INTO t2 VALUES
620
  (1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15');
621
622
SELECT * FROM t1, t2 
623
  WHERE t1.day BETWEEN 
624
               '2005.09.01' - INTERVAL 6 MONTH AND t2.day;
625
SELECT * FROM t1, t2 
626
  WHERE CAST(t1.day AS DATE) BETWEEN 
627
                             '2005.09.01' - INTERVAL 6 MONTH AND t2.day;
628
 
629
DROP TABLE t1,t2;
630
631
#
632
# Bug #22229: bug in DATE_ADD()
633
#
634
635
select str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE;
636
637
#
638
# Bug #21103: DATE column not compared as DATE
639
#
640
641
create table t1 (field DATE);
642
insert into t1 values ('2006-11-06');
643
select * from t1 where field < '2006-11-06 04:08:36.0'; 
644
select * from t1 where field = '2006-11-06 04:08:36.0'; 
645
select * from t1 where field = '2006-11-06'; 
646
select * from t1 where CAST(field as DATETIME) < '2006-11-06 04:08:36.0';
647
select * from t1 where CAST(field as DATE) < '2006-11-06 04:08:36.0';
648
drop table t1;
649
650
#
651
# Bug #25643: SEC_TO_TIME function problem
652
#
653
CREATE TABLE t1 (a int, t1 time, t2 time, d date, PRIMARY KEY  (a));
654
INSERT INTO t1 VALUES (1, '10:00:00', NULL, NULL), 
655
       (2, '11:00:00', '11:15:00', '1972-02-06');
656
SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d) 
657
  FROM t1;
658
SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d)
659
  FROM t1 ORDER BY a DESC;
660
DROP TABLE t1;
661
662
#
663
# Bug #20293: group by cuts off value from time_format
664
#
665
# Check if using GROUP BY with TIME_FORMAT() produces correct results
666
667
SELECT TIME_FORMAT(SEC_TO_TIME(a),"%H:%i:%s") FROM (SELECT 3020399 AS a UNION SELECT 3020398 ) x GROUP BY 1;
668
669
#
670
# Bug#32180: DATE_ADD treats datetime numeric argument as DATE
671
#            instead of DATETIME
672
#
673
674
select DATE_ADD('20071108181000', INTERVAL 1 DAY);
675
select DATE_ADD(20071108181000,   INTERVAL 1 DAY);
676
select DATE_ADD('20071108',       INTERVAL 1 DAY);
677
select DATE_ADD(20071108,         INTERVAL 1 DAY);
678
679
#
680
# Bug#32770: LAST_DAY() returns a DATE, but somehow internally keeps
681
#            track of the TIME.
682
#
683
684
select LAST_DAY('2007-12-06 08:59:19.05') - INTERVAL 1 SECOND;
685
686
#
687
# Bug#33834: FRAC_SECOND: Applicability not clear in documentation
688
#
689
# Show that he use of FRAC_SECOND, for anything other than
690
# TIMESTAMPADD / TIMESTAMPDIFF, is a server error.
691
692
# mysqltest.c discards an expected 'deprecated' warning on prepare stage
693
SELECT TIMESTAMPADD(FRAC_SECOND, 1, '2008-02-18');
694
SELECT TIMESTAMPDIFF(FRAC_SECOND, '2008-02-17', '2008-02-18');
695
696
--error ER_PARSE_ERROR
697
SELECT DATE_ADD('2008-02-18', INTERVAL 1 FRAC_SECOND);
698
--error ER_PARSE_ERROR
699
SELECT DATE_SUB('2008-02-18', INTERVAL 1 FRAC_SECOND);
700
701
--error ER_PARSE_ERROR
702
SELECT '2008-02-18' + INTERVAL 1 FRAC_SECOND;
703
--error ER_PARSE_ERROR
704
SELECT '2008-02-18' - INTERVAL 1 FRAC_SECOND;
705
706
--echo End of 5.0 tests
707
708
#
709
# Bug #18997
710
#
711
712
select date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND);
713
select date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND);
714
select date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND);
715
select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND);
716
select date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND);
717
select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND);
718
select date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR);
719
select date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND);
720
select date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND);
721
select date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND);
722
select date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND);
723
724
725
--echo End of 5.1 tests