Skip to content

Commit

Permalink
expression: fix comparation between uint and int (pingcap#6028)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored and shenli committed Mar 13, 2018
1 parent a0eb1bb commit 337a45b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -1800,13 +1800,13 @@ func compareInt(ctx sessionctx.Context, args []Expression, row types.Row) (val i
case isUnsigned0 && isUnsigned1:
res = types.CompareUint64(uint64(arg0), uint64(arg1))
case isUnsigned0 && !isUnsigned1:
if arg1 < 0 || arg0 > math.MaxInt64 {
if arg1 < 0 || uint64(arg0) > math.MaxInt64 {
res = 1
} else {
res = types.CompareInt64(arg0, arg1)
}
case !isUnsigned0 && isUnsigned1:
if arg0 < 0 || arg1 > math.MaxInt64 {
if arg0 < 0 || uint64(arg1) > math.MaxInt64 {
res = -1
} else {
res = types.CompareInt64(arg0, arg1)
Expand Down
2 changes: 2 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2665,6 +2665,8 @@ func (s *testIntegrationSuite) TestCompareBuiltin(c *C) {
result = tk.MustQuery(`select least(cast("2017-01-01" as datetime), "123", "234", cast("2018-01-01" as date)), least(cast("2017-01-01" as date), "123", null)`)
result.Check(testkit.Rows("123 <nil>"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1105|invalid time format", "Warning|1105|invalid time format", "Warning|1105|invalid time format"))

tk.MustQuery(`select 1 < 17666000000000000000, 1 > 17666000000000000000, 1 = 17666000000000000000`).Check(testkit.Rows("1 0 0"))
}

func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) {
Expand Down

0 comments on commit 337a45b

Please sign in to comment.