drop table if exists t1;
create table t1 (y year,y2 year(2));
insert into t1 values (0,0),(1999,1999),(2000,2000),(2001,2001),(70,70),(69,69);
select * from t1;
y	y2
0000	00
1999	99
2000	00
2001	01
1970	70
2069	69
select * from t1 order by y;
y	y2
0000	00
1970	70
1999	99
2000	00
2001	01
2069	69
select * from t1 order by y2;
y	y2
1970	70
1999	99
0000	00
2000	00
2001	01
2069	69
drop table t1;
create table t1 (y year);
insert into t1 values (now());
Warnings:
Warning	1265	Data truncated for column 'y' at row 1
select if(y = now(), 1, 0) from t1;
if(y = now(), 1, 0)
1
drop table t1;
create table t1(a year);
insert into t1 values (2000.5), ('2000.5'), ('2001a'), ('2.001E3');
Warnings:
Warning	1265	Data truncated for column 'a' at row 3
select * from t1;
a
2001
2001
2001
2001
drop table t1;
End of 5.0 tests
#
# Bug #49480: WHERE using YEAR columns returns unexpected results
#
CREATE TABLE t2(yy YEAR(2), c2 CHAR(4));
CREATE TABLE t4(yyyy YEAR(4), c4 CHAR(4));
INSERT INTO t2 (c2) VALUES (NULL),(1970),(1999),(2000),(2001),(2069);
INSERT INTO t4 (c4) SELECT c2 FROM t2;
UPDATE t2 SET yy = c2;
UPDATE t4 SET yyyy = c4;
SELECT * FROM t2;
yy	c2
NULL	NULL
70	1970
99	1999
00	2000
01	2001
69	2069
SELECT * FROM t4;
yyyy	c4
NULL	NULL
1970	1970
1999	1999
2000	2000
2001	2001
2069	2069
# Comparison of YEAR(2) with YEAR(4)
SELECT * FROM t2, t4 WHERE yy = yyyy;
yy	c2	yyyy	c4
70	1970	1970	1970
99	1999	1999	1999
00	2000	2000	2000
01	2001	2001	2001
69	2069	2069	2069
SELECT * FROM t2, t4 WHERE yy <=> yyyy;
yy	c2	yyyy	c4
NULL	NULL	NULL	NULL
70	1970	1970	1970
99	1999	1999	1999
00	2000	2000	2000
01	2001	2001	2001
69	2069	2069	2069
SELECT * FROM t2, t4 WHERE yy < yyyy;
yy	c2	yyyy	c4
70	1970	1999	1999
70	1970	2000	2000
99	1999	2000	2000
70	1970	2001	2001
99	1999	2001	2001
00	2000	2001	2001
70	1970	2069	2069
99	1999	2069	2069
00	2000	2069	2069
01	2001	2069	2069
SELECT * FROM t2, t4 WHERE yy > yyyy;
yy	c2	yyyy	c4
99	1999	1970	1970
00	2000	1970	1970
01	2001	1970	1970
69	2069	1970	1970
00	2000	1999	1999
01	2001	1999	1999
69	2069	1999	1999
01	2001	2000	2000
69	2069	2000	2000
69	2069	2001	2001
# Comparison of YEAR(2) with YEAR(2)
SELECT * FROM t2 a, t2 b WHERE a.yy = b.yy;
yy	c2	yy	c2
70	1970	70	1970
99	1999	99	1999
00	2000	00	2000
01	2001	01	2001
69	2069	69	2069
SELECT * FROM t2 a, t2 b WHERE a.yy <=> b.yy;
yy	c2	yy	c2
NULL	NULL	NULL	NULL
70	1970	70	1970
99	1999	99	1999
00	2000	00	2000
01	2001	01	2001
69	2069	69	2069
SELECT * FROM t2 a, t2 b WHERE a.yy < b.yy;
yy	c2	yy	c2
70	1970	99	1999
70	1970	00	2000
99	1999	00	2000
70	1970	01	2001
99	1999	01	2001
00	2000	01	2001
70	1970	69	2069
99	1999	69	2069
00	2000	69	2069
01	2001	69	2069
# Comparison of YEAR(4) with YEAR(4)
SELECT * FROM t4 a, t4 b WHERE a.yyyy = b.yyyy;
yyyy	c4	yyyy	c4
1970	1970	1970	1970
1999	1999	1999	1999
2000	2000	2000	2000
2001	2001	2001	2001
2069	2069	2069	2069
SELECT * FROM t4 a, t4 b WHERE a.yyyy <=> b.yyyy;
yyyy	c4	yyyy	c4
NULL	NULL	NULL	NULL
1970	1970	1970	1970
1999	1999	1999	1999
2000	2000	2000	2000
2001	2001	2001	2001
2069	2069	2069	2069
SELECT * FROM t4 a, t4 b WHERE a.yyyy < b.yyyy;
yyyy	c4	yyyy	c4
1970	1970	1999	1999
1970	1970	2000	2000
1999	1999	2000	2000
1970	1970	2001	2001
1999	1999	2001	2001
2000	2000	2001	2001
1970	1970	2069	2069
1999	1999	2069	2069
2000	2000	2069	2069
2001	2001	2069	2069
# Comparison with constants:
SELECT * FROM t2 WHERE yy = NULL;
yy	c2
SELECT * FROM t4 WHERE yyyy = NULL;
yyyy	c4
SELECT * FROM t2 WHERE yy <=> NULL;
yy	c2
NULL	NULL
SELECT * FROM t4 WHERE yyyy <=> NULL;
yyyy	c4
NULL	NULL
SELECT * FROM t2 WHERE yy < NULL;
yy	c2
SELECT * FROM t2 WHERE yy > NULL;
yy	c2
SELECT * FROM t2 WHERE yy = NOW();
yy	c2
SELECT * FROM t4 WHERE yyyy = NOW();
yyyy	c4
SELECT * FROM t2 WHERE yy = 99;
yy	c2
99	1999
SELECT * FROM t2 WHERE 99 = yy;
yy	c2
99	1999
SELECT * FROM t4 WHERE yyyy = 99;
yyyy	c4
1999	1999
SELECT * FROM t2 WHERE yy = 'test';
yy	c2
00	2000
Warnings:
Warning	1292	Truncated incorrect DOUBLE value: 'test'
SELECT * FROM t4 WHERE yyyy = 'test';
yyyy	c4
Warnings:
Warning	1292	Truncated incorrect DOUBLE value: 'test'
SELECT * FROM t2 WHERE yy = '1999';
yy	c2
99	1999
SELECT * FROM t4 WHERE yyyy = '1999';
yyyy	c4
1999	1999
SELECT * FROM t2 WHERE yy = 1999;
yy	c2
99	1999
SELECT * FROM t4 WHERE yyyy = 1999;
yyyy	c4
1999	1999
SELECT * FROM t2 WHERE yy = 1999.1;
yy	c2
99	1999
SELECT * FROM t4 WHERE yyyy = 1999.1;
yyyy	c4
1999	1999
SELECT * FROM t2 WHERE yy = 1998.9;
yy	c2
99	1999
SELECT * FROM t4 WHERE yyyy = 1998.9;
yyyy	c4
1999	1999
# Coverage tests for YEAR with zero/2000 constants:
SELECT * FROM t2 WHERE yy = 0;
yy	c2
00	2000
SELECT * FROM t2 WHERE yy = '0';
yy	c2
00	2000
SELECT * FROM t2 WHERE yy = '0000';
yy	c2
00	2000
SELECT * FROM t2 WHERE yy = '2000';
yy	c2
00	2000
SELECT * FROM t2 WHERE yy = 2000;
yy	c2
00	2000
SELECT * FROM t4 WHERE yyyy = 0;
yyyy	c4
SELECT * FROM t4 WHERE yyyy = '0';
yyyy	c4
2000	2000
SELECT * FROM t4 WHERE yyyy = '0000';
yyyy	c4
SELECT * FROM t4 WHERE yyyy = '2000';
yyyy	c4
2000	2000
SELECT * FROM t4 WHERE yyyy = 2000;
yyyy	c4
2000	2000
# Comparison with constants those are out of YEAR range
# (coverage test for backward compatibility)
SELECT COUNT(yy) FROM t2;
COUNT(yy)
5
SELECT COUNT(yyyy) FROM t4;
COUNT(yyyy)
5
SELECT COUNT(*) FROM t2 WHERE yy = -1;
COUNT(*)
0
SELECT COUNT(*) FROM t4 WHERE yyyy > -1;
COUNT(*)
5
SELECT COUNT(*) FROM t2 WHERE yy > -1000000000000000000;
COUNT(*)
5
SELECT COUNT(*) FROM t4 WHERE yyyy > -1000000000000000000;
COUNT(*)
5
SELECT COUNT(*) FROM t2 WHERE yy < 2156;
COUNT(*)
5
SELECT COUNT(*) FROM t4 WHERE yyyy < 2156;
COUNT(*)
5
SELECT COUNT(*) FROM t2 WHERE yy < 1000000000000000000;
COUNT(*)
5
SELECT COUNT(*) FROM t4 WHERE yyyy < 1000000000000000000;
COUNT(*)
5
SELECT * FROM t2 WHERE yy < 123;
yy	c2
70	1970
99	1999
00	2000
01	2001
69	2069
SELECT * FROM t2 WHERE yy > 123;
yy	c2
SELECT * FROM t4 WHERE yyyy < 123;
yyyy	c4
SELECT * FROM t4 WHERE yyyy > 123;
yyyy	c4
1970	1970
1999	1999
2000	2000
2001	2001
2069	2069
DROP TABLE t2, t4;
#
End of 5.1 tests
