~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to mysql-test/r/type_datetime.result

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1;
 
2
create table t1 (t datetime);
 
3
insert into t1 values (101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030100000000),(20030000000000);
 
4
select * from t1;
 
5
t
 
6
2000-01-01 00:00:00
 
7
2069-12-31 00:00:00
 
8
1970-01-01 00:00:00
 
9
1999-12-31 00:00:00
 
10
1000-01-01 00:00:00
 
11
9999-12-31 00:00:00
 
12
2000-01-01 00:00:00
 
13
2069-12-31 00:00:00
 
14
1970-01-01 00:00:00
 
15
1999-12-31 23:59:59
 
16
1000-01-01 00:00:00
 
17
9999-12-31 23:59:59
 
18
2003-01-00 00:00:00
 
19
2003-00-00 00:00:00
 
20
delete from t1 where t > 0;
 
21
optimize table t1;
 
22
Table   Op      Msg_type        Msg_text
 
23
test.t1 optimize        status  OK
 
24
check table t1;
 
25
Table   Op      Msg_type        Msg_text
 
26
test.t1 check   status  OK
 
27
delete from t1;
 
28
insert into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030100000000"),("20030000000000");
 
29
insert into t1 values ("2003-003-03");
 
30
insert into t1 values ("20030102T131415"),("2001-01-01T01:01:01"), ("2001-1-1T1:01:01");
 
31
select * from t1;
 
32
t
 
33
2000-01-01 00:00:00
 
34
2069-12-31 00:00:00
 
35
1970-01-01 00:00:00
 
36
1999-12-31 00:00:00
 
37
0000-01-01 00:00:00
 
38
0001-01-01 00:00:00
 
39
9999-12-31 00:00:00
 
40
2000-10-10 00:00:00
 
41
2069-12-31 00:00:00
 
42
1970-01-01 00:00:00
 
43
1999-12-31 23:59:59
 
44
1000-01-01 00:00:00
 
45
9999-12-31 23:59:59
 
46
2003-01-00 00:00:00
 
47
2003-00-00 00:00:00
 
48
2003-03-03 00:00:00
 
49
2003-01-02 13:14:15
 
50
2001-01-01 01:01:01
 
51
2001-01-01 01:01:01
 
52
truncate table t1;
 
53
insert into t1 values("2003-0303 12:13:14");
 
54
Warnings:
 
55
Warning 1264    Out of range value for column 't' at row 1
 
56
select * from t1;
 
57
t
 
58
0000-00-00 00:00:00
 
59
drop table t1;
 
60
CREATE TABLE t1 (a timestamp, b date, c time, d datetime);
 
61
insert into t1 (b,c,d) values(now(),curtime(),now());
 
62
Warnings:
 
63
Note    1265    Data truncated for column 'b' at row 1
 
64
select date_format(a,"%Y-%m-%d")=b,right(a+0,6)=c+0,a=d+0 from t1;
 
65
date_format(a,"%Y-%m-%d")=b     right(a+0,6)=c+0        a=d+0
 
66
1       1       1
 
67
drop table t1;
 
68
CREATE TABLE t1 (a datetime not null);
 
69
insert into t1 values (0);
 
70
select * from t1 where a is null;
 
71
a
 
72
0000-00-00 00:00:00
 
73
drop table t1;
 
74
create table t1 (id int, dt datetime);
 
75
insert into t1 values (1,"2001-08-14 00:00:00"),(2,"2001-08-15 00:00:00"),(3,"2001-08-16 00:00:00"),(4,"2003-09-15 01:20:30");
 
76
select * from t1 where dt='2001-08-14 00:00:00' and dt =  if(id=1,'2001-08-14 00:00:00','1999-08-15');
 
77
id      dt
 
78
1       2001-08-14 00:00:00
 
79
create index dt on t1 (dt);
 
80
select * from t1 where dt > 20021020;
 
81
id      dt
 
82
4       2003-09-15 01:20:30
 
83
select * from t1 ignore index (dt) where dt > 20021020;
 
84
id      dt
 
85
4       2003-09-15 01:20:30
 
86
drop table t1;
 
87
CREATE TABLE `t1` (
 
88
`date` datetime NOT NULL default '0000-00-00 00:00:00',
 
89
`numfacture` int(6) unsigned NOT NULL default '0',
 
90
`expedition` datetime NOT NULL default '0000-00-00 00:00:00',
 
91
PRIMARY KEY  (`numfacture`),
 
92
KEY `date` (`date`),
 
93
KEY `expedition` (`expedition`)
 
94
) ENGINE=MyISAM;
 
95
INSERT INTO t1 (expedition) VALUES ('0001-00-00 00:00:00');
 
96
SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
 
97
date    numfacture      expedition
 
98
0000-00-00 00:00:00     0       0001-00-00 00:00:00
 
99
INSERT INTO t1 (numfacture,expedition) VALUES ('1212','0001-00-00 00:00:00');
 
100
SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
 
101
date    numfacture      expedition
 
102
0000-00-00 00:00:00     0       0001-00-00 00:00:00
 
103
0000-00-00 00:00:00     1212    0001-00-00 00:00:00
 
104
EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
 
105
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
106
1       SIMPLE  t1      ref     expedition      expedition      8       const   1       
 
107
drop table t1;
 
108
create table t1 (a datetime not null, b datetime not null);
 
109
insert into t1 values (now(), now());
 
110
insert into t1 values (now(), now());
 
111
select * from t1 where a is null or b is null;
 
112
a       b
 
113
drop table t1;
 
114
create table t1 (t datetime);
 
115
insert into t1 values (20030102030460),(20030102036301),(20030102240401),
 
116
(20030132030401),(20031302030401),(100001202030401);
 
117
Warnings:
 
118
Warning 1264    Out of range value for column 't' at row 1
 
119
Warning 1264    Out of range value for column 't' at row 2
 
120
Warning 1264    Out of range value for column 't' at row 3
 
121
Warning 1264    Out of range value for column 't' at row 4
 
122
Warning 1264    Out of range value for column 't' at row 5
 
123
Warning 1264    Out of range value for column 't' at row 6
 
124
select * from t1;
 
125
t
 
126
0000-00-00 00:00:00
 
127
0000-00-00 00:00:00
 
128
0000-00-00 00:00:00
 
129
0000-00-00 00:00:00
 
130
0000-00-00 00:00:00
 
131
0000-00-00 00:00:00
 
132
delete from t1;
 
133
insert into t1 values
 
134
("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"),
 
135
("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00");
 
136
Warnings:
 
137
Warning 1264    Out of range value for column 't' at row 1
 
138
Warning 1264    Out of range value for column 't' at row 2
 
139
Warning 1264    Out of range value for column 't' at row 3
 
140
Warning 1264    Out of range value for column 't' at row 4
 
141
Warning 1264    Out of range value for column 't' at row 5
 
142
Warning 1264    Out of range value for column 't' at row 6
 
143
select * from t1;
 
144
t
 
145
0000-00-00 00:00:00
 
146
0000-00-00 00:00:00
 
147
0000-00-00 00:00:00
 
148
0000-00-00 00:00:00
 
149
0000-00-00 00:00:00
 
150
0000-00-00 00:00:00
 
151
delete from t1;
 
152
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
 
153
Warnings:
 
154
Warning 1264    Out of range value for column 't' at row 1
 
155
Warning 1264    Out of range value for column 't' at row 2
 
156
select * from t1 order by t;
 
157
t
 
158
0000-00-00 00:00:00
 
159
2003-01-01 00:00:00
 
160
drop table t1;
 
161
create table t1 (dt datetime);
 
162
insert into t1 values ("12-00-00"), ("00-00-00 01:00:00");
 
163
insert into t1 values ("00-00-00"), ("00-00-00 00:00:00");
 
164
select * from t1;
 
165
dt
 
166
2012-00-00 00:00:00
 
167
2000-00-00 01:00:00
 
168
0000-00-00 00:00:00
 
169
0000-00-00 00:00:00
 
170
drop table t1;
 
171
select cast('2006-12-05 22:10:10' as datetime) + 0;
 
172
cast('2006-12-05 22:10:10' as datetime) + 0
 
173
20061205221010.000000
 
174
CREATE TABLE t1(a DATETIME NOT NULL);
 
175
INSERT INTO t1 VALUES ('20060606155555');
 
176
SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555");
 
177
a
 
178
2006-06-06 15:55:55
 
179
PREPARE s FROM 'SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555")';
 
180
EXECUTE s;
 
181
a
 
182
2006-06-06 15:55:55
 
183
DROP PREPARE s;
 
184
DROP TABLE t1;
 
185
SELECT CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6));
 
186
CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6))
 
187
20060810.000000
 
188
SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6));
 
189
CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6))
 
190
20060810101112.000000
 
191
SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6));
 
192
CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6))
 
193
20060810101112.000014
 
194
SELECT CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6));
 
195
CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6))
 
196
101112.098700
 
197
set @org_mode=@@sql_mode;
 
198
create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03');
 
199
Warnings:
 
200
Note    1265    Data truncated for column 'da' at row 1
 
201
show create table t1;
 
202
Table   Create Table
 
203
t1      CREATE TABLE `t1` (
 
204
  `da` date DEFAULT '1962-03-03',
 
205
  `dt` datetime DEFAULT '1962-03-03 00:00:00'
 
206
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
207
insert into t1 values ();
 
208
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
 
209
Warnings:
 
210
Note    1265    Data truncated for column 'da' at row 1
 
211
set @@sql_mode='ansi,traditional';
 
212
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
 
213
Warnings:
 
214
Note    1265    Data truncated for column 'da' at row 1
 
215
insert into t1 set dt='2007-03-23 13:49:38',da=dt;
 
216
Warnings:
 
217
Note    1265    Data truncated for column 'da' at row 1
 
218
insert into t1 values ('2007-03-32','2007-03-23 13:49:38');
 
219
ERROR 22007: Incorrect date value: '2007-03-32' for column 'da' at row 1
 
220
select * from t1;
 
221
da      dt
 
222
1962-03-03      1962-03-03 00:00:00
 
223
2007-03-23      2007-03-23 13:49:38
 
224
2007-03-23      2007-03-23 13:49:38
 
225
2007-03-23      2007-03-23 13:49:38
 
226
drop table t1;
 
227
create table t1 (da date default '1962-03-32 23:33:34', dt datetime default '1962-03-03');
 
228
ERROR 42000: Invalid default value for 'da'
 
229
create table t1 (t time default '916:00:00 a');
 
230
ERROR 42000: Invalid default value for 't'
 
231
set @@sql_mode= @org_mode;
 
232
create table t1 (f1 date, f2 datetime, f3 timestamp);
 
233
insert into t1(f1) values(curdate());
 
234
select curdate() < now(), f1 < now(), cast(f1 as date) < now() from t1;
 
235
curdate() < now()       f1 < now()      cast(f1 as date) < now()
 
236
1       1       1
 
237
delete from t1;
 
238
insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');
 
239
insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');
 
240
insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');
 
241
insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');
 
242
insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');
 
243
select f1, f3 from t1 where f1 >= '2001-02-05 00:00:00' and f3 <= '2001-04-15';
 
244
f1      f3
 
245
2001-02-05      2001-02-05 01:01:01
 
246
2001-03-10      2001-03-10 01:01:01
 
247
2001-04-15      2001-04-15 00:00:00
 
248
select f1, f3 from t1 where f1 >= '2001-2-5 0:0:0' and f2 <= '2001-4-15';
 
249
f1      f3
 
250
2001-02-05      2001-02-05 01:01:01
 
251
2001-03-10      2001-03-10 01:01:01
 
252
2001-04-15      2001-04-15 00:00:00
 
253
select f1, f2 from t1 where if(1, f1, 0) >= f2;
 
254
f1      f2
 
255
2001-02-05      2001-02-05 00:00:00
 
256
2001-03-10      2001-03-09 01:01:01
 
257
2001-04-15      2001-04-15 00:00:00
 
258
select 1 from dual where cast('2001-1-1 2:3:4' as date) = cast('2001-01-01' as datetime);
 
259
1
 
260
1
 
261
select f1, f2, f1 > f2, f1 = f2, f1 < f2 from t1;
 
262
f1      f2      f1 > f2 f1 = f2 f1 < f2
 
263
2001-01-01      2001-01-01 01:01:01     0       0       1
 
264
2001-02-05      2001-02-05 00:00:00     0       1       0
 
265
2001-03-10      2001-03-09 01:01:01     1       0       0
 
266
2001-04-15      2001-04-15 00:00:00     0       1       0
 
267
2001-05-20      2001-05-20 01:01:01     0       0       1
 
268
drop table t1;
 
269
create table t1 (f1 date, f2 datetime, f3 timestamp);
 
270
insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');
 
271
insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');
 
272
insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');
 
273
insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');
 
274
insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');
 
275
select f2 from t1 where f2 between '2001-2-5' and '01-04-14';
 
276
f2
 
277
2001-02-05 00:00:00
 
278
2001-03-09 01:01:01
 
279
select f1, f2, f3 from t1 where f1 between f2 and f3;
 
280
f1      f2      f3
 
281
2001-02-05      2001-02-05 00:00:00     2001-02-05 01:01:01
 
282
2001-03-10      2001-03-09 01:01:01     2001-03-10 01:01:01
 
283
2001-04-15      2001-04-15 00:00:00     2001-04-15 00:00:00
 
284
select f1, f2, f3 from t1 where cast(f1 as datetime) between f2 and
 
285
cast(f3 as date);
 
286
f1      f2      f3
 
287
2001-02-05      2001-02-05 00:00:00     2001-02-05 01:01:01
 
288
2001-03-10      2001-03-09 01:01:01     2001-03-10 01:01:01
 
289
2001-04-15      2001-04-15 00:00:00     2001-04-15 00:00:00
 
290
select f2 from t1 where '2001-04-10 12:34:56' between f2 and '01-05-01';
 
291
f2
 
292
2001-01-01 01:01:01
 
293
2001-02-05 00:00:00
 
294
2001-03-09 01:01:01
 
295
select f2, f3 from t1 where '01-03-10' between f2 and f3;
 
296
f2      f3
 
297
2001-03-09 01:01:01     2001-03-10 01:01:01
 
298
select f2 from t1 where DATE(f2) between "2001-4-15" AND "01-4-15";
 
299
f2
 
300
2001-04-15 00:00:00
 
301
SELECT 1 from dual where NOW() BETWEEN CURRENT_DATE() - INTERVAL 1 DAY AND CURRENT_DATE();
 
302
1
 
303
drop table t1;
 
304
create table t1 (f1 date);
 
305
insert into t1 values('01-01-01'),('01-01-02'),('01-01-03');
 
306
select * from t1 where f1 in ('01-01-01','2001-01-02','2001-01-03 00:00:00');
 
307
f1
 
308
2001-01-01
 
309
2001-01-02
 
310
2001-01-03
 
311
create table t2(f2 datetime);
 
312
insert into t2 values('01-01-01 00:00:00'),('01-02-03 12:34:56'),('02-04-06 11:22:33');
 
313
select * from t2 where f2 in ('01-01-01','01-02-03 12:34:56','01-02-03');
 
314
f2
 
315
2001-01-01 00:00:00
 
316
2001-02-03 12:34:56
 
317
select * from t1,t2 where '01-01-02' in (f1, cast(f2 as date));
 
318
f1      f2
 
319
2001-01-02      2001-01-01 00:00:00
 
320
2001-01-02      2001-02-03 12:34:56
 
321
2001-01-02      2002-04-06 11:22:33
 
322
select * from t1,t2 where '01-01-01' in (f1, '01-02-03');
 
323
f1      f2
 
324
2001-01-01      2001-01-01 00:00:00
 
325
2001-01-01      2001-02-03 12:34:56
 
326
2001-01-01      2002-04-06 11:22:33
 
327
select * from t1,t2 where if(1,'01-02-03 12:34:56','') in (f1, f2);
 
328
f1      f2
 
329
2001-01-01      2001-02-03 12:34:56
 
330
2001-01-02      2001-02-03 12:34:56
 
331
2001-01-03      2001-02-03 12:34:56
 
332
create table t3(f3 varchar(20));
 
333
insert into t3 select * from t2;
 
334
select * from t2,t3 where f2 in (f3,'03-04-05');
 
335
f2      f3
 
336
2001-01-01 00:00:00     2001-01-01 00:00:00
 
337
2001-02-03 12:34:56     2001-02-03 12:34:56
 
338
2002-04-06 11:22:33     2002-04-06 11:22:33
 
339
select f1,f2,f3 from t1,t2,t3 where (f1,'1') in ((f2,'1'),(f3,'1'));
 
340
f1      f2      f3
 
341
2001-01-01      2001-01-01 00:00:00     2001-01-01 00:00:00
 
342
2001-01-01      2001-02-03 12:34:56     2001-01-01 00:00:00
 
343
2001-01-01      2002-04-06 11:22:33     2001-01-01 00:00:00
 
344
2001-01-01      2001-01-01 00:00:00     2001-02-03 12:34:56
 
345
2001-01-01      2001-01-01 00:00:00     2002-04-06 11:22:33
 
346
select f1 from t1 where ('1',f1) in (('1','01-01-01'),('1','2001-1-1 0:0:0'),('1','02-02-02'));
 
347
f1
 
348
2001-01-01
 
349
drop table t1,t2,t3;
 
350
select least(cast('01-01-01' as date), '01-01-02');
 
351
least(cast('01-01-01' as date), '01-01-02')
 
352
2001-01-01
 
353
select greatest(cast('01-01-01' as date), '01-01-02');
 
354
greatest(cast('01-01-01' as date), '01-01-02')
 
355
01-01-02
 
356
select least(cast('01-01-01' as date), '01-01-02') + 0;
 
357
least(cast('01-01-01' as date), '01-01-02') + 0
 
358
20010101
 
359
select greatest(cast('01-01-01' as date), '01-01-02') + 0;
 
360
greatest(cast('01-01-01' as date), '01-01-02') + 0
 
361
20010102
 
362
select least(cast('01-01-01' as datetime), '01-01-02') + 0;
 
363
least(cast('01-01-01' as datetime), '01-01-02') + 0
 
364
20010101000000
 
365
select cast(least(cast('01-01-01' as datetime), '01-01-02') as signed);
 
366
cast(least(cast('01-01-01' as datetime), '01-01-02') as signed)
 
367
20010101000000
 
368
select cast(least(cast('01-01-01' as datetime), '01-01-02') as decimal(16,2));
 
369
cast(least(cast('01-01-01' as datetime), '01-01-02') as decimal(16,2))
 
370
20010101000000.00
 
371
DROP PROCEDURE IF EXISTS test27759 ;
 
372
CREATE PROCEDURE test27759()
 
373
BEGIN
 
374
declare v_a date default '2007-4-10';
 
375
declare v_b date default '2007-4-11';
 
376
declare v_c datetime default '2004-4-9 0:0:0';
 
377
select v_a as a,v_b as b,
 
378
least( v_a, v_b ) as a_then_b,
 
379
least( v_b, v_a ) as b_then_a,
 
380
least( v_c, v_a ) as c_then_a;
 
381
END;|
 
382
call test27759();
 
383
a       b       a_then_b        b_then_a        c_then_a
 
384
2007-04-10      2007-04-11      2007-04-10      2007-04-10      2004-04-09 00:00:00
 
385
drop procedure test27759;
 
386
create table t1 (f1 date);
 
387
insert into t1 values (curdate());
 
388
select left(f1,10) = curdate() from t1;
 
389
left(f1,10) = curdate()
 
390
1
 
391
drop table t1;
 
392
create table t1(f1 date);
 
393
insert into t1 values('01-01-01'),('02-02-02'),('01-01-01'),('02-02-02');
 
394
set @bug28261='';
 
395
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
 
396
if(@bug28261 = f1, '', @bug28261:= f1)
 
397
2001-01-01
 
398
2002-02-02
 
399
2001-01-01
 
400
2002-02-02
 
401
Warnings:
 
402
Warning 1292    Incorrect date value: '' for column 'f1' at row 1
 
403
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
 
404
if(@bug28261 = f1, '', @bug28261:= f1)
 
405
2001-01-01
 
406
2002-02-02
 
407
2001-01-01
 
408
2002-02-02
 
409
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
 
410
if(@bug28261 = f1, '', @bug28261:= f1)
 
411
2001-01-01
 
412
2002-02-02
 
413
2001-01-01
 
414
2002-02-02
 
415
drop table t1;
 
416
create table t1(f1 datetime);
 
417
insert into t1 values('2001-01-01'),('2002-02-02');
 
418
select * from t1 where f1 between 20020101 and 20070101000000;
 
419
f1
 
420
2002-02-02 00:00:00
 
421
select * from t1 where f1 between 2002010 and 20070101000000;
 
422
f1
 
423
2001-01-01 00:00:00
 
424
2002-02-02 00:00:00
 
425
Warnings:
 
426
Warning 1292    Incorrect datetime value: '2002010' for column 'f1' at row 1
 
427
select * from t1 where f1 between 20020101 and 2007010100000;
 
428
f1
 
429
Warnings:
 
430
Warning 1292    Incorrect datetime value: '2007010100000' for column 'f1' at row 1
 
431
drop table t1;
 
432
#
 
433
# Bug#27216: functions with parameters of different date types may
 
434
#            return wrong type of the result.
 
435
#
 
436
create table t1 (f1 date, f2 datetime, f3 varchar(20));
 
437
create table t2 as select coalesce(f1,f1) as f4 from t1;
 
438
desc t2;
 
439
Field   Type    Null    Key     Default Extra
 
440
f4      date    YES             NULL    
 
441
create table t3 as select coalesce(f1,f2) as f4 from t1;
 
442
desc t3;
 
443
Field   Type    Null    Key     Default Extra
 
444
f4      datetime        YES             NULL    
 
445
create table t4 as select coalesce(f2,f2) as f4 from t1;
 
446
desc t4;
 
447
Field   Type    Null    Key     Default Extra
 
448
f4      datetime        YES             NULL    
 
449
create table t5 as select coalesce(f1,f3) as f4 from t1;
 
450
desc t5;
 
451
Field   Type    Null    Key     Default Extra
 
452
f4      varbinary(20)   YES             NULL    
 
453
create table t6 as select coalesce(f2,f3) as f4 from t1;
 
454
desc t6;
 
455
Field   Type    Null    Key     Default Extra
 
456
f4      varbinary(20)   YES             NULL    
 
457
create table t7 as select coalesce(makedate(1997,1),f2) as f4 from t1;
 
458
desc t7;
 
459
Field   Type    Null    Key     Default Extra
 
460
f4      datetime        YES             NULL    
 
461
create table t8 as select coalesce(cast('01-01-01' as datetime),f2) as f4
 
462
from t1;
 
463
desc t8;
 
464
Field   Type    Null    Key     Default Extra
 
465
f4      datetime        YES             NULL    
 
466
create table t9 as select case when 1 then cast('01-01-01' as date)
 
467
when 0 then cast('01-01-01' as date) end as f4 from t1;
 
468
desc t9;
 
469
Field   Type    Null    Key     Default Extra
 
470
f4      date    YES             NULL    
 
471
create table t10 as select case when 1 then cast('01-01-01' as datetime)
 
472
when 0 then cast('01-01-01' as datetime) end as f4 from t1;
 
473
desc t10;
 
474
Field   Type    Null    Key     Default Extra
 
475
f4      datetime        YES             NULL    
 
476
create table t11 as select if(1, cast('01-01-01' as datetime),
 
477
cast('01-01-01' as date)) as f4 from t1;
 
478
desc t11;
 
479
Field   Type    Null    Key     Default Extra
 
480
f4      datetime        YES             NULL    
 
481
create table t12 as select least(cast('01-01-01' as datetime),
 
482
cast('01-01-01' as date)) as f4 from t1;
 
483
desc t12;
 
484
Field   Type    Null    Key     Default Extra
 
485
f4      datetime        YES             NULL    
 
486
create table t13 as select ifnull(cast('01-01-01' as datetime),
 
487
cast('01-01-01' as date)) as f4 from t1;
 
488
desc t13;
 
489
Field   Type    Null    Key     Default Extra
 
490
f4      datetime        YES             NULL    
 
491
drop tables t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13;
 
492
###################################################################
 
493
create table t1 (f1 time);
 
494
insert into t1 set f1 = '45:44:44';
 
495
insert into t1 set f1 = '15:44:44';
 
496
select * from t1 where (convert(f1,datetime)) != 1;
 
497
f1
 
498
15:44:44
 
499
Warnings:
 
500
Warning 1292    Incorrect datetime value: '0000-00-00 45:44:44'
 
501
drop table t1;
 
502
create table t1 (a tinyint);
 
503
insert into t1 values (), (), ();
 
504
select sum(a) from t1 group by convert(a, datetime);
 
505
sum(a)
 
506
NULL
 
507
drop table t1;
 
508
create table t1 (id int(10) not null, cur_date datetime not null);
 
509
create table t2 (id int(10) not null, cur_date date not null);
 
510
insert into t1 (id, cur_date) values (1, '2007-04-25 18:30:22');
 
511
insert into t2 (id, cur_date) values (1, '2007-04-25');
 
512
set @@optimizer_switch=no_semijoin;
 
513
explain extended
 
514
select * from t1
 
515
where id in (select id from t1 as x1 where (t1.cur_date is null));
 
516
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
517
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
 
518
2       DEPENDENT SUBQUERY      NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
 
519
Warnings:
 
520
Note    1276    Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
 
521
Note    1003    select '1' AS `id`,'2007-04-25 18:30:22' AS `cur_date` from `test`.`t1` where <in_optimizer>('1',<exists>(select 1 AS `Not_used` from `test`.`t1` `x1` where 0))
 
522
select * from t1
 
523
where id in (select id from t1 as x1 where (t1.cur_date is null));
 
524
id      cur_date
 
525
explain extended
 
526
select * from t2
 
527
where id in (select id from t2 as x1 where (t2.cur_date is null));
 
528
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
529
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
 
530
2       DEPENDENT SUBQUERY      NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
 
531
Warnings:
 
532
Note    1276    Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
 
533
Note    1003    select '1' AS `id`,'2007-04-25' AS `cur_date` from `test`.`t2` where <in_optimizer>('1',<exists>(select 1 AS `Not_used` from `test`.`t2` `x1` where 0))
 
534
select * from t2
 
535
where id in (select id from t2 as x1 where (t2.cur_date is null));
 
536
id      cur_date
 
537
insert into t1 (id, cur_date) values (2, '2007-04-26 18:30:22');
 
538
insert into t2 (id, cur_date) values (2, '2007-04-26');
 
539
explain extended
 
540
select * from t1
 
541
where id in (select id from t1 as x1 where (t1.cur_date is null));
 
542
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
543
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
544
2       DEPENDENT SUBQUERY      x1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
545
Warnings:
 
546
Note    1276    Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
 
547
Note    1003    select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`id`,<exists>(select 1 AS `Not_used` from `test`.`t1` `x1` where ((`test`.`t1`.`cur_date` = 0) and (<cache>(`test`.`t1`.`id`) = `test`.`x1`.`id`))))
 
548
select * from t1
 
549
where id in (select id from t1 as x1 where (t1.cur_date is null));
 
550
id      cur_date
 
551
explain extended
 
552
select * from t2
 
553
where id in (select id from t2 as x1 where (t2.cur_date is null));
 
554
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
 
555
1       PRIMARY t2      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
556
2       DEPENDENT SUBQUERY      x1      ALL     NULL    NULL    NULL    NULL    2       100.00  Using where
 
557
Warnings:
 
558
Note    1276    Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
 
559
Note    1003    select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 AS `Not_used` from `test`.`t2` `x1` where ((`test`.`t2`.`cur_date` = 0) and (<cache>(`test`.`t2`.`id`) = `test`.`x1`.`id`))))
 
560
select * from t2
 
561
where id in (select id from t2 as x1 where (t2.cur_date is null));
 
562
id      cur_date
 
563
set @@optimizer_switch='';
 
564
drop table t1,t2;
 
565
End of 5.0 tests
 
566
set @org_mode=@@sql_mode;
 
567
create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03');
 
568
Warnings:
 
569
Note    1265    Data truncated for column 'da' at row 1
 
570
show create table t1;
 
571
Table   Create Table
 
572
t1      CREATE TABLE `t1` (
 
573
  `da` date DEFAULT '1962-03-03',
 
574
  `dt` datetime DEFAULT '1962-03-03 00:00:00'
 
575
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
576
insert into t1 values ();
 
577
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
 
578
Warnings:
 
579
Note    1265    Data truncated for column 'da' at row 1
 
580
set @@sql_mode='ansi,traditional';
 
581
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
 
582
Warnings:
 
583
Note    1265    Data truncated for column 'da' at row 1
 
584
insert into t1 set dt='2007-03-23 13:49:38',da=dt;
 
585
Warnings:
 
586
Note    1265    Data truncated for column 'da' at row 1
 
587
insert into t1 values ('2007-03-32','2007-03-23 13:49:38');
 
588
ERROR 22007: Incorrect date value: '2007-03-32' for column 'da' at row 1
 
589
select * from t1;
 
590
da      dt
 
591
1962-03-03      1962-03-03 00:00:00
 
592
2007-03-23      2007-03-23 13:49:38
 
593
2007-03-23      2007-03-23 13:49:38
 
594
2007-03-23      2007-03-23 13:49:38
 
595
drop table t1;
 
596
create table t1 (da date default '1962-03-32 23:33:34', dt datetime default '1962-03-03');
 
597
ERROR 42000: Invalid default value for 'da'
 
598
create table t1 (t time default '916:00:00 a');
 
599
ERROR 42000: Invalid default value for 't'
 
600
set @@sql_mode= @org_mode;