diff --git a/enginetest/queries/script_queries.go b/enginetest/queries/script_queries.go index 660742c9cd..6a481282b5 100644 --- a/enginetest/queries/script_queries.go +++ b/enginetest/queries/script_queries.go @@ -244,6 +244,8 @@ var ScriptTests = []ScriptTest{ "INSERT INTO t2(c0) VALUES (-32768);", "CREATE TABLE t3(c0 TINYINT);", "INSERT INTO t3(c0) VALUES (-128);", + "CREATE TABLE tab1 (col4 INT)", + "INSERT INTO tab1 VALUES (10), (20), (30)", }, Assertions: []ScriptTestAssertion{ { @@ -311,6 +313,10 @@ var ScriptTests = []ScriptTest{ Expected: []sql.Row{{int64(-128)}}, ExpectedColumns: sql.Schema{{Name: "-(-CAST(-128 AS SIGNED))", Type: types.Int64}}, }, + { + Query: "SELECT * FROM tab1 AS cor0 WHERE NOT - CAST(NULL AS SIGNED) < +35 * +col4 + - -39", + Expected: []sql.Row{}, + }, }, }, { diff --git a/sql/expression/arithmetic.go b/sql/expression/arithmetic.go index 61fc9a49a9..f4a4c101ae 100644 --- a/sql/expression/arithmetic.go +++ b/sql/expression/arithmetic.go @@ -757,8 +757,9 @@ func (e *UnaryMinus) Type() sql.Type { typ = types.Int64 case types.Int64: if lit, ok := e.Child.(*Literal); ok { - if lit.Value().(int64) == math.MinInt64 { - typ = types.InternalDecimalType + // lit.Value() can be nil + if v, ok := lit.Value().(int64); ok && v == math.MinInt64 { + return types.InternalDecimalType } } }