Commit 268c7a35 authored by kaa@polly.local's avatar kaa@polly.local
Browse files

Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various functions

- Honor unsigned_flag in the corresponding functions
- Use compare_int_signed_unsigned()/compare_int_unsigned_signed() instead of explicit comparison in GREATEST() and LEAST()
parent b6cd727e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -177,3 +177,9 @@ from t1 where b=3 group by b;
min(a)	min(case when 1=1 then a else NULL end)	min(case when 1!=1 then NULL else a end)
2	2	2
drop table t1;
SELECT CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END;
CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END
18446744073709551615
SELECT COALESCE(18446744073709551615);
COALESCE(18446744073709551615)
18446744073709551615
+6 −0
Original line number Diff line number Diff line
@@ -99,3 +99,9 @@ a NULLIF(a,'')
NULL	NULL
	NULL
DROP TABLE t1;
SELECT IF(1 != 0, 18446744073709551615, 1);
IF(1 != 0, 18446744073709551615, 1)
18446744073709551615
SELECT IFNULL(NULL, 18446744073709551615);
IFNULL(NULL, 18446744073709551615)
18446744073709551615
+6 −0
Original line number Diff line number Diff line
@@ -183,3 +183,9 @@ select 5.1 mod 3, 5.1 mod -3, -5.1 mod 3, -5.1 mod -3;
select 5 mod 3, 5 mod -3, -5 mod 3, -5 mod -3;
5 mod 3	5 mod -3	-5 mod 3	-5 mod -3
2	2	-2	-2
SELECT GREATEST(1, 18446744073709551615);
GREATEST(1, 18446744073709551615)
18446744073709551615
SELECT LEAST(1, 18446744073709551615);
LEAST(1, 18446744073709551615)
1
+4 −0
Original line number Diff line number Diff line
@@ -203,3 +203,7 @@ select @@global.version;
select @@session.VERSION;
@@session.VERSION
#
set @a=18446744073709551615;
select @a;
@a
18446744073709551615
+6 −0
Original line number Diff line number Diff line
@@ -130,4 +130,10 @@ select min(a), min(case when 1=1 then a else NULL end),
from t1 where b=3 group by b;
drop table t1;

#
# Bug #20924: UNSIGNED values in CASE and COALESCE are treated as SIGNED
#
SELECT CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END;
SELECT COALESCE(18446744073709551615);

# End of 4.1 tests
Loading