summaryrefslogtreecommitdiff
path: root/mysql-test/main/timezone2.result
blob: b858e761a81c63b419c1ad3aa798779e3166e364 (plain)
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
drop table if exists t1, t2;
drop function if exists f1;
create table t1 (ts timestamp);
set time_zone='+00:00';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp())
0
insert into t1 (ts) values ('2003-03-30 02:30:00');
set time_zone='+10:30';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp())
-37800
insert into t1 (ts) values ('2003-03-30 02:30:00');
set time_zone='-10:00';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp())
36000
insert into t1 (ts) values ('2003-03-30 02:30:00');
select * from t1;
ts
2003-03-29 16:30:00
2003-03-29 06:00:00
2003-03-30 02:30:00
drop table t1;
select Name from mysql.time_zone_name where Name in 
('UTC','Universal','MET','Europe/Moscow','leap/Europe/Moscow');
Name
Europe/Moscow
leap/Europe/Moscow
MET
Universal
UTC
create table t1 (i int, ts timestamp);
set time_zone='MET';
insert into t1 (i, ts) values
(unix_timestamp('2003-03-01 00:00:00'),'2003-03-01 00:00:00');
insert into t1 (i, ts) values
(unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'),
(unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'),
(unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00');
Warnings:
Warning	1299	Invalid TIMESTAMP value in column 'ts' at row 2
insert into t1 (i, ts) values
(unix_timestamp(20030330015959),20030330015959),
(unix_timestamp(20030330023000),20030330023000),
(unix_timestamp(20030330030000),20030330030000);
Warnings:
Warning	1299	Invalid TIMESTAMP value in column 'ts' at row 2
insert into t1 (i, ts) values
(unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00');
insert into t1 (i, ts) values
(unix_timestamp('2003-10-26 01:00:00'),'2003-10-26 01:00:00'),
(unix_timestamp('2003-10-26 02:00:00'),'2003-10-26 02:00:00'),
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59'),
(unix_timestamp('2003-10-26 04:00:00'),'2003-10-26 04:00:00'),
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59');
set time_zone='UTC';
select * from t1;
i	ts
1046473200	2003-02-28 23:00:00
1048985999	2003-03-30 00:59:59
1048986000	2003-03-30 01:00:00
1048986000	2003-03-30 01:00:00
1048985999	2003-03-30 00:59:59
1048986000	2003-03-30 01:00:00
1048986000	2003-03-30 01:00:00
1051740000	2003-04-30 22:00:00
1067122800	2003-10-25 23:00:00
1067126400	2003-10-26 00:00:00
1067129999	2003-10-26 00:59:59
1067137200	2003-10-26 03:00:00
1067129999	2003-10-26 00:59:59
truncate table t1;
set time_zone='Europe/Moscow';
insert into t1 (i, ts) values
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
Warnings:
Warning	1299	Invalid TIMESTAMP value in column 'ts' at row 2
select * from t1;
i	ts
1072904400	2004-01-01 00:00:00
1080428400	2004-03-28 03:00:00
1091304000	2003-08-01 00:00:00
1099175400	2004-10-31 02:30:00
truncate table t1;
set time_zone='leap/Europe/Moscow';
insert into t1 (i, ts) values
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
Warnings:
Warning	1299	Invalid TIMESTAMP value in column 'ts' at row 2
select * from t1;
i	ts
1072904422	2004-01-01 00:00:00
1080428422	2004-03-28 03:00:00
1091304022	2003-08-01 00:00:00
1099175422	2004-10-31 02:30:00
truncate table t1;
insert into t1 (i, ts) values
(unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'),
(unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00');
select * from t1;
i	ts
362793608	1981-07-01 03:59:59
362793610	1981-07-01 04:00:00
select from_unixtime(362793609);
from_unixtime(362793609)
1981-07-01 03:59:59
drop table t1;
create table t1 (ts timestamp);
set time_zone='UTC';
insert into t1 values ('0000-00-00 00:00:00'),('1969-12-31 23:59:59'),
('1970-01-01 00:00:00'),('1970-01-01 00:00:01'),
('2038-01-19 03:14:07'),('2038-01-19 03:14:08');
Warnings:
Warning	1264	Out of range value for column 'ts' at row 2
Warning	1264	Out of range value for column 'ts' at row 3
Warning	1264	Out of range value for column 'ts' at row 6
select * from t1;
ts
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
1970-01-01 00:00:01
2038-01-19 03:14:07
0000-00-00 00:00:00
truncate table t1;
set time_zone='MET';
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 00:30:00'),
('1970-01-01 01:00:00'),('1970-01-01 01:00:01'),
('2038-01-19 04:14:07'),('2038-01-19 04:14:08');
Warnings:
Warning	1264	Out of range value for column 'ts' at row 2
Warning	1264	Out of range value for column 'ts' at row 3
Warning	1264	Out of range value for column 'ts' at row 6
select * from t1;
ts
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
1970-01-01 01:00:01
2038-01-19 04:14:07
0000-00-00 00:00:00
truncate table t1;
set time_zone='+01:30';
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 01:00:00'),
('1970-01-01 01:30:00'),('1970-01-01 01:30:01'),
('2038-01-19 04:44:07'),('2038-01-19 04:44:08');
Warnings:
Warning	1264	Out of range value for column 'ts' at row 2
Warning	1264	Out of range value for column 'ts' at row 3
Warning	1264	Out of range value for column 'ts' at row 6
select * from t1;
ts
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
1970-01-01 01:30:01
2038-01-19 04:44:07
0000-00-00 00:00:00
drop table t1;
show variables like 'time_zone';
Variable_name	Value
time_zone	+01:30
set time_zone = default;
show variables like 'time_zone';
Variable_name	Value
time_zone	SYSTEM
set time_zone= '0';
ERROR HY000: Unknown or incorrect time zone: '0'
set time_zone= '0:0';
ERROR HY000: Unknown or incorrect time zone: '0:0'
set time_zone= '-20:00';
ERROR HY000: Unknown or incorrect time zone: '-20:00'
set time_zone= '+20:00';
ERROR HY000: Unknown or incorrect time zone: '+20:00'
set time_zone= 'Some/Unknown/Time/Zone';
ERROR HY000: Unknown or incorrect time zone: 'Some/Unknown/Time/Zone'
select convert_tz(now(),'UTC', 'Universal') = now();
convert_tz(now(),'UTC', 'Universal') = now()
1
select convert_tz(now(),'utc', 'UTC') = now();
convert_tz(now(),'utc', 'UTC') = now()
1
select convert_tz('1917-11-07 12:00:00', 'MET', 'UTC');
convert_tz('1917-11-07 12:00:00', 'MET', 'UTC')
1917-11-07 12:00:00
select convert_tz('1970-01-01 01:00:00', 'MET', 'UTC');
convert_tz('1970-01-01 01:00:00', 'MET', 'UTC')
1970-01-01 01:00:00
select convert_tz('1970-01-01 01:00:01', 'MET', 'UTC');
convert_tz('1970-01-01 01:00:01', 'MET', 'UTC')
1970-01-01 00:00:01
select convert_tz('2003-03-01 00:00:00', 'MET', 'UTC');
convert_tz('2003-03-01 00:00:00', 'MET', 'UTC')
2003-02-28 23:00:00
select convert_tz('2003-03-30 01:59:59', 'MET', 'UTC');
convert_tz('2003-03-30 01:59:59', 'MET', 'UTC')
2003-03-30 00:59:59
select convert_tz('2003-03-30 02:30:00', 'MET', 'UTC');
convert_tz('2003-03-30 02:30:00', 'MET', 'UTC')
2003-03-30 01:00:00
select convert_tz('2003-03-30 03:00:00', 'MET', 'UTC');
convert_tz('2003-03-30 03:00:00', 'MET', 'UTC')
2003-03-30 01:00:00
select convert_tz('2003-05-01 00:00:00', 'MET', 'UTC');
convert_tz('2003-05-01 00:00:00', 'MET', 'UTC')
2003-04-30 22:00:00
select convert_tz('2003-10-26 01:00:00', 'MET', 'UTC');
convert_tz('2003-10-26 01:00:00', 'MET', 'UTC')
2003-10-25 23:00:00
select convert_tz('2003-10-26 02:00:00', 'MET', 'UTC');
convert_tz('2003-10-26 02:00:00', 'MET', 'UTC')
2003-10-26 00:00:00
select convert_tz('2003-10-26 02:59:59', 'MET', 'UTC');
convert_tz('2003-10-26 02:59:59', 'MET', 'UTC')
2003-10-26 00:59:59
select convert_tz('2003-10-26 04:00:00', 'MET', 'UTC');
convert_tz('2003-10-26 04:00:00', 'MET', 'UTC')
2003-10-26 03:00:00
select convert_tz('2038-01-19 04:14:07', 'MET', 'UTC');
convert_tz('2038-01-19 04:14:07', 'MET', 'UTC')
2038-01-19 03:14:07
select convert_tz('2038-01-19 04:14:08', 'MET', 'UTC');
convert_tz('2038-01-19 04:14:08', 'MET', 'UTC')
2038-01-19 04:14:08
select convert_tz('2103-01-01 04:00:00', 'MET', 'UTC');
convert_tz('2103-01-01 04:00:00', 'MET', 'UTC')
2103-01-01 04:00:00
create table t1 (tz varchar(3));
insert into t1 (tz) values ('MET'), ('UTC');
select tz, convert_tz('2003-12-31 00:00:00',tz,'UTC'), convert_tz('2003-12-31 00:00:00','UTC',tz) from t1 order by tz;
tz	convert_tz('2003-12-31 00:00:00',tz,'UTC')	convert_tz('2003-12-31 00:00:00','UTC',tz)
MET	2003-12-30 23:00:00	2003-12-31 01:00:00
UTC	2003-12-31 00:00:00	2003-12-31 00:00:00
drop table t1;
select convert_tz('2003-12-31 04:00:00', NULL, 'UTC');
convert_tz('2003-12-31 04:00:00', NULL, 'UTC')
NULL
select convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC');
convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC')
NULL
select convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone');
convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone')
NULL
select convert_tz('2003-12-31 04:00:00', 'MET', NULL);
convert_tz('2003-12-31 04:00:00', 'MET', NULL)
NULL
select convert_tz( NULL, 'MET', 'UTC');
convert_tz( NULL, 'MET', 'UTC')
NULL
create table t1 (ts timestamp);
set timestamp=1000000000;
insert into t1 (ts) values (now());
select convert_tz(ts, @@time_zone, 'Japan') from t1;
convert_tz(ts, @@time_zone, 'Japan')
2001-09-09 10:46:40
drop table t1;
select convert_tz('2005-01-14 17:00:00', 'UTC', custTimeZone) from (select 'UTC' as custTimeZone) as tmp;
convert_tz('2005-01-14 17:00:00', 'UTC', custTimeZone)
2005-01-14 17:00:00
create table t1 select convert_tz(NULL, NULL, NULL);
select * from t1;
convert_tz(NULL, NULL, NULL)
NULL
drop table t1;
SET @old_log_bin_trust_function_creators = @@global.log_bin_trust_function_creators;
SET GLOBAL log_bin_trust_function_creators = 1;
create table t1 (ldt datetime, udt datetime);
create function f1(i datetime) returns datetime
return convert_tz(i, 'UTC', 'Europe/Moscow');
create trigger t1_bi before insert on t1 for each row
set new.udt:= convert_tz(new.ldt, 'Europe/Moscow', 'UTC');
insert into t1 (ldt) values ('2006-04-19 16:30:00');
select * from t1;
ldt	udt
2006-04-19 16:30:00	2006-04-19 12:30:00
select ldt, f1(udt) as ldt2 from t1;
ldt	ldt2
2006-04-19 16:30:00	2006-04-19 16:30:00
drop table t1;
drop function f1;
SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (t TIMESTAMP);
INSERT INTO t1 VALUES (NULL), (NULL);
LOCK TABLES t1 WRITE;
SELECT CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow') IS NULL;
CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow') IS NULL
0
UPDATE t1 SET t = CONVERT_TZ(t, 'UTC', 'Europe/Moscow');
UNLOCK TABLES;
DROP TABLE t1;
#
# Bug #55424: convert_tz crashes when fed invalid data
#
CREATE TABLE t1 (a SET('x') NOT NULL);
INSERT INTO t1 VALUES ('');
SELECT CONVERT_TZ(1, a, 1) FROM t1;
CONVERT_TZ(1, a, 1)
NULL
SELECT CONVERT_TZ(1, 1, a) FROM t1;
CONVERT_TZ(1, 1, a)
NULL
DROP TABLE t1;
End of 5.1 tests
#
# Start of 5.3 tests
#
#
# MDEV-4653 Wrong result for CONVERT_TZ(TIME('00:00:00'),'+00:00','+7:5')
#
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
SELECT CONVERT_TZ(TIME('00:00:00'),'+00:00','+7:5');
CONVERT_TZ(TIME('00:00:00'),'+00:00','+7:5')
2001-02-03 07:05:00
SELECT CONVERT_TZ(TIME('2010-01-01 00:00:00'),'+00:00','+7:5');
CONVERT_TZ(TIME('2010-01-01 00:00:00'),'+00:00','+7:5')
2001-02-03 07:05:00
SET timestamp=DEFAULT;
#
# MDEV-5506 safe_mutex: Trying to lock unitialized mutex at safemalloc.c on server shutdown after SELECT with CONVERT_TZ
#
SELECT CONVERT_TZ('2001-10-08 00:00:00', MAKE_SET(0,'+01:00'), '+00:00' );
CONVERT_TZ('2001-10-08 00:00:00', MAKE_SET(0,'+01:00'), '+00:00' )
NULL
#
# End of 5.3 tests
#
#
# Start of 10.1 tests
#
#
# MDEV-11895 NO_ZERO_DATE affects timestamp values without any warnings
#
SET sql_mode = '';
CREATE TABLE t1 (a TIMESTAMP NULL) ENGINE = MyISAM;
CREATE TABLE t2 (a TIMESTAMP NULL) ENGINE = MyISAM;
CREATE TABLE t3 (a TIMESTAMP NULL) ENGINE = MyISAM;
SET @@session.time_zone = 'UTC';
INSERT INTO t1 VALUES ('2011-10-29 23:00:00');
INSERT INTO t1 VALUES ('2011-10-29 23:00:01');
INSERT INTO t1 VALUES ('2011-10-29 23:59:59');
SET @@session.time_zone = 'Europe/Moscow';
SET sql_mode='NO_ZERO_DATE';
INSERT INTO t2 SELECT * FROM t1;
SET sql_mode='';
INSERT INTO t3 SELECT * FROM t1;
SELECT UNIX_TIMESTAMP(a), a FROM t2;
UNIX_TIMESTAMP(a)	a
1319929200	2011-10-30 02:00:00
1319929201	2011-10-30 02:00:01
1319932799	2011-10-30 02:59:59
SELECT UNIX_TIMESTAMP(a), a FROM t3;
UNIX_TIMESTAMP(a)	a
1319929200	2011-10-30 02:00:00
1319929201	2011-10-30 02:00:01
1319932799	2011-10-30 02:59:59
DROP TABLE t1, t2, t3;
#
# End of 10.1 tests
#
#
# Start of 10.4 tests
#
#
# MDEV-17203 Move fractional second truncation from Item_xxx_typecast::get_date() to Time and Datetime constructors
# (an addition for the test for MDEV-4653)
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
SET old_mode=ZERO_DATE_TIME_CAST;
SELECT CONVERT_TZ(TIME('00:00:00'),'+00:00','+7:5');
CONVERT_TZ(TIME('00:00:00'),'+00:00','+7:5')
NULL
Warnings:
Warning	1292	Truncated incorrect datetime value: '00:00:00'
SELECT CONVERT_TZ(TIME('2010-01-01 00:00:00'),'+00:00','+7:5');
CONVERT_TZ(TIME('2010-01-01 00:00:00'),'+00:00','+7:5')
NULL
Warnings:
Warning	1292	Truncated incorrect datetime value: '00:00:00'
SET old_mode=DEFAULT;
SET timestamp=DEFAULT;
#
# MDEV-13995 MAX(timestamp) returns a wrong result near DST change
#
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526)      /*summer time in Moscow*/);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526+3599) /*winter time in Moscow*/);
SET time_zone='Europe/Moscow';
SELECT a, UNIX_TIMESTAMP(a) FROM t1;
a	UNIX_TIMESTAMP(a)
2010-10-31 02:25:26	1288477526
2010-10-31 02:25:25	1288481125
SELECT UNIX_TIMESTAMP(MAX(a)) AS a FROM t1;
a
1288481125
CREATE TABLE t2 (a TIMESTAMP);
INSERT INTO t2 SELECT MAX(a) AS a FROM t1;
SELECT a, UNIX_TIMESTAMP(a) FROM t2;
a	UNIX_TIMESTAMP(a)
2010-10-31 02:25:25	1288481125
DROP TABLE t2;
DROP TABLE t1;
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP);
CREATE TABLE t2 (a TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526)      /*summer time in Moscow*/);
INSERT INTO t2 VALUES (FROM_UNIXTIME(1288477526+3599) /*winter time in Moscow*/);
SET time_zone='Europe/Moscow';
SELECT UNIX_TIMESTAMP(t1.a), UNIX_TIMESTAMP(t2.a) FROM t1,t2;
UNIX_TIMESTAMP(t1.a)	UNIX_TIMESTAMP(t2.a)
1288477526	1288481125
SELECT * FROM t1,t2 WHERE t1.a < t2.a;
a	a
2010-10-31 02:25:26	2010-10-31 02:25:25
DROP TABLE t1,t2;
BEGIN NOT ATOMIC
DECLARE a,b TIMESTAMP;
SET time_zone='+00:00';
SET a=FROM_UNIXTIME(1288477526);
SET b=FROM_UNIXTIME(1288481125);
SELECT a < b;
SET time_zone='Europe/Moscow';
SELECT a < b;
END;
$$
a < b
1
a < b
1
CREATE OR REPLACE FUNCTION f1(uts INT) RETURNS TIMESTAMP
BEGIN
DECLARE ts TIMESTAMP;
DECLARE tz VARCHAR(64) DEFAULT @@time_zone;
SET time_zone='+00:00';
SET ts=FROM_UNIXTIME(uts);
SET time_zone=tz;
RETURN ts;
END;
$$
SET time_zone='+00:00';
SELECT f1(1288477526) < f1(1288481125);
f1(1288477526) < f1(1288481125)
1
SET time_zone='Europe/Moscow';
SELECT f1(1288477526) < f1(1288481125);
f1(1288477526) < f1(1288481125)
1
DROP FUNCTION f1;
CREATE TABLE t1 (a TIMESTAMP,b TIMESTAMP);
SET time_zone='+00:00';
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526) /*summer time in Mowcow*/,
FROM_UNIXTIME(1288481125) /*winter time in Moscow*/);
SELECT *, LEAST(a,b) FROM t1;
a	b	LEAST(a,b)
2010-10-30 22:25:26	2010-10-30 23:25:25	2010-10-30 22:25:26
SET time_zone='Europe/Moscow';
SELECT *, LEAST(a,b) FROM t1;
a	b	LEAST(a,b)
2010-10-31 02:25:26	2010-10-31 02:25:25	2010-10-31 02:25:26
SELECT UNIX_TIMESTAMP(a), UNIX_TIMESTAMP(b), UNIX_TIMESTAMP(LEAST(a,b)) FROM t1;
UNIX_TIMESTAMP(a)	UNIX_TIMESTAMP(b)	UNIX_TIMESTAMP(LEAST(a,b))
1288477526	1288481125	1288477526
DROP TABLE t1;
CREATE TABLE t1 (a TIMESTAMP,b TIMESTAMP,c TIMESTAMP);
SET time_zone='+00:00';
INSERT INTO t1 VALUES (
FROM_UNIXTIME(1288477526) /*summer time in Moscow*/,
FROM_UNIXTIME(1288481125) /*winter time in Moscow*/,
FROM_UNIXTIME(1288481126) /*winter time in Moscow*/);
SELECT b BETWEEN a AND c FROM t1;
b BETWEEN a AND c
1
SET time_zone='Europe/Moscow';
SELECT b BETWEEN a AND c FROM t1;
b BETWEEN a AND c
1
DROP TABLE t1;
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526) /*summer time in Mowcow*/);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288481125) /*winter time in Moscow*/);
SELECT a, UNIX_TIMESTAMP(a) FROM t1 ORDER BY a;
a	UNIX_TIMESTAMP(a)
2010-10-30 22:25:26	1288477526
2010-10-30 23:25:25	1288481125
SELECT COALESCE(a) AS a, UNIX_TIMESTAMP(a) FROM t1 ORDER BY a;
a	UNIX_TIMESTAMP(a)
2010-10-30 22:25:26	1288477526
2010-10-30 23:25:25	1288481125
SET time_zone='Europe/Moscow';
SELECT a, UNIX_TIMESTAMP(a) FROM t1 ORDER BY a;
a	UNIX_TIMESTAMP(a)
2010-10-31 02:25:26	1288477526
2010-10-31 02:25:25	1288481125
SELECT COALESCE(a) AS a, UNIX_TIMESTAMP(a) FROM t1 ORDER BY a;
a	UNIX_TIMESTAMP(a)
2010-10-31 02:25:26	1288477526
2010-10-31 02:25:25	1288481125
DROP TABLE t1;
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526) /*summer time in Mowcow*/);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288481126) /*winter time in Moscow*/);
SET time_zone='Europe/Moscow';
SELECT a, UNIX_TIMESTAMP(a) FROM t1 GROUP BY a;
a	UNIX_TIMESTAMP(a)
2010-10-31 02:25:26	1288477526
2010-10-31 02:25:26	1288481126
DROP TABLE t1;
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP, b TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526),FROM_UNIXTIME(1288481126));
SELECT UNIX_TIMESTAMP(a),UNIX_TIMESTAMP(b),CASE a WHEN b THEN 'eq' ELSE 'ne' END AS x FROM t1;
UNIX_TIMESTAMP(a)	UNIX_TIMESTAMP(b)	x
1288477526	1288481126	ne
SET time_zone='Europe/Moscow';
SELECT UNIX_TIMESTAMP(a),UNIX_TIMESTAMP(b),CASE a WHEN b THEN 'eq' ELSE 'ne' END AS x FROM t1;
UNIX_TIMESTAMP(a)	UNIX_TIMESTAMP(b)	x
1288477526	1288481126	ne
DROP TABLE t1;
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP, b TIMESTAMP,c TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526),FROM_UNIXTIME(1288481126),FROM_UNIXTIME(1288481127));
SELECT UNIX_TIMESTAMP(a),UNIX_TIMESTAMP(b),a IN (b,c) AS x FROM t1;
UNIX_TIMESTAMP(a)	UNIX_TIMESTAMP(b)	x
1288477526	1288481126	0
SET time_zone='Europe/Moscow';
SELECT UNIX_TIMESTAMP(a),UNIX_TIMESTAMP(b),a IN (b,c) AS x FROM t1;
UNIX_TIMESTAMP(a)	UNIX_TIMESTAMP(b)	x
1288477526	1288481126	0
DROP TABLE t1;
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP, b TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526),FROM_UNIXTIME(1288481126));
SELECT * FROM t1 WHERE a = (SELECT MAX(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a = (SELECT MIN(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a IN ((SELECT MAX(b) FROM t1), (SELECT MIN(b) FROM t1));
a	b
SET time_zone='Europe/Moscow';
SELECT * FROM t1 WHERE a = (SELECT MAX(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a = (SELECT MIN(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a IN ((SELECT MAX(b) FROM t1), (SELECT MIN(b) FROM t1));
a	b
DROP TABLE t1;
SET time_zone='+00:00';
CREATE TABLE t1 (a TIMESTAMP, b TIMESTAMP);
INSERT INTO t1 VALUES (FROM_UNIXTIME(1100000000),FROM_UNIXTIME(1200000000));
INSERT INTO t1 VALUES (FROM_UNIXTIME(1100000001),FROM_UNIXTIME(1200000001));
INSERT INTO t1 VALUES (FROM_UNIXTIME(1288477526),FROM_UNIXTIME(1288481126));
INSERT INTO t1 VALUES (FROM_UNIXTIME(1300000000),FROM_UNIXTIME(1400000000));
INSERT INTO t1 VALUES (FROM_UNIXTIME(1300000001),FROM_UNIXTIME(1400000001));
SELECT * FROM t1 WHERE a = (SELECT MAX(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a = (SELECT MIN(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a IN ((SELECT MAX(b) FROM t1), (SELECT MIN(b) FROM t1));
a	b
SET time_zone='Europe/Moscow';
SELECT * FROM t1 WHERE a = (SELECT MAX(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a = (SELECT MIN(b) FROM t1);
a	b
SELECT * FROM t1 WHERE a IN ((SELECT MAX(b) FROM t1), (SELECT MIN(b) FROM t1));
a	b
DROP TABLE t1;
#
# MDEV-17979 Assertion `0' failed in Item::val_native upon SELECT with timestamp, NULLIF, GROUP BY
#
SET time_zone='+00:00';
CREATE TABLE t1 (a INT, ts TIMESTAMP) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1, FROM_UNIXTIME(1288481126) /*winter time in Moscow*/);
SET time_zone='Europe/Moscow';
CREATE TABLE t2 AS SELECT ts, COALESCE(ts) AS cts FROM t1 GROUP BY cts;
SELECT ts, cts, UNIX_TIMESTAMP(ts) AS uts, UNIX_TIMESTAMP(cts) AS ucts FROM t2;
ts	cts	uts	ucts
2010-10-31 02:25:26	2010-10-31 02:25:26	1288481126	1288481126
DROP TABLE t1,t2;
SET time_zone=DEFAULT;
#
# MDEV-19961 MIN(timestamp_column) returns a wrong result in a GROUP BY query
#
SET time_zone='Europe/Moscow';
CREATE OR REPLACE TABLE t1 (i INT, d TIMESTAMP);
SET timestamp=1288477526  /* this is summer time */ ;
INSERT INTO t1 VALUES (3,NULL);
SET timestamp=1288477526+3599 /* this is winter time*/ ;
INSERT INTO t1 VALUES (3,NULL);
SELECT i, d, UNIX_TIMESTAMP(d) FROM t1 ORDER BY d;
i	d	UNIX_TIMESTAMP(d)
3	2010-10-31 02:25:26	1288477526
3	2010-10-31 02:25:25	1288481125
SELECT i, MIN(d) FROM t1 GROUP BY i;
i	MIN(d)
3	2010-10-31 02:25:26
SELECT i, MAX(d) FROM t1 GROUP BY i;
i	MAX(d)
3	2010-10-31 02:25:25
DROP TABLE t1;
SET timestamp=DEFAULT;
SET time_zone=DEFAULT;
#
# MDEV-20397 Support TIMESTAMP, DATETIME, TIME in ROUND() and TRUNCATE()
#
SET time_zone='Europe/Moscow';
CREATE TABLE t1 (i INT, d TIMESTAMP(6));
SET timestamp=1288479599.999999  /* this is the last second in summer time */ ;
INSERT INTO t1 VALUES (1,NULL);
SET timestamp=1288479600.000000 /* this is the first second in winter time */ ;
INSERT INTO t1 VALUES (2,NULL);
SELECT i, d, UNIX_TIMESTAMP(d) FROM t1 ORDER BY d;
i	d	UNIX_TIMESTAMP(d)
1	2010-10-31 02:59:59.999999	1288479599.999999
2	2010-10-31 02:00:00.000000	1288479600.000000
CREATE TABLE t2 (i INT, d TIMESTAMP, expected_unix_timestamp INT UNSIGNED);
INSERT INTO t2 SELECT i, ROUND(d) AS d, ROUND(UNIX_TIMESTAMP(d)) FROM t1;
# UNIX_TIMESTAMP(d) and expected_unix_timestamp should return the same value.
# Currently they do not, because ROUND(timestamp) is performed as DATETIME.
# We should fix this eventually.
SELECT i, d, UNIX_TIMESTAMP(d), expected_unix_timestamp FROM t2 ORDER BY i;
i	d	UNIX_TIMESTAMP(d)	expected_unix_timestamp
1	2010-10-31 03:00:00	1288483200	1288479600
2	2010-10-31 02:00:00	1288476000	1288479600
DROP TABLE t2;
DROP TABLE t1;
SET timestamp=DEFAULT;
SET time_zone=DEFAULT;
#
# End of 10.4 tests
#