Skip to content

Commit 31b74b2

Browse files
authored
Merge pull request #3262 from dolthub/elian/9927b
dolthub/dolt#9927: Fix SQL regression on UnaryMinus NULL CAST
2 parents da991de + f08573f commit 31b74b2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

enginetest/queries/script_queries.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ var ScriptTests = []ScriptTest{
244244
"INSERT INTO t2(c0) VALUES (-32768);",
245245
"CREATE TABLE t3(c0 TINYINT);",
246246
"INSERT INTO t3(c0) VALUES (-128);",
247+
"CREATE TABLE tab1 (col4 INT)",
248+
"INSERT INTO tab1 VALUES (10), (20), (30)",
247249
},
248250
Assertions: []ScriptTestAssertion{
249251
{
@@ -311,6 +313,10 @@ var ScriptTests = []ScriptTest{
311313
Expected: []sql.Row{{int64(-128)}},
312314
ExpectedColumns: sql.Schema{{Name: "-(-CAST(-128 AS SIGNED))", Type: types.Int64}},
313315
},
316+
{
317+
Query: "SELECT * FROM tab1 AS cor0 WHERE NOT - CAST(NULL AS SIGNED) < +35 * +col4 + - -39",
318+
Expected: []sql.Row{},
319+
},
314320
},
315321
},
316322
{

sql/expression/arithmetic.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,9 @@ func (e *UnaryMinus) Type() sql.Type {
757757
typ = types.Int64
758758
case types.Int64:
759759
if lit, ok := e.Child.(*Literal); ok {
760-
if lit.Value().(int64) == math.MinInt64 {
761-
typ = types.InternalDecimalType
760+
// lit.Value() can be nil
761+
if v, ok := lit.Value().(int64); ok && v == math.MinInt64 {
762+
return types.InternalDecimalType
762763
}
763764
}
764765
}

0 commit comments

Comments
 (0)