Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
sql/expression: handle null values in arithmetic expressions
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
  • Loading branch information
erizocosmico committed Jun 21, 2019
1 parent 9722f31 commit 540082d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,10 @@ var queries = []struct {
`SELECT CASE i WHEN 1 THEN i ELSE NULL END FROM mytable`,
[]sql.Row{{int64(1)}, {nil}, {nil}},
},
{
`SELECT (NULL+1)`,
[]sql.Row{{nil}},
},
}

func TestQueries(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions sql/expression/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func (a *Arithmetic) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, err
}

if lval == nil || rval == nil {
return nil, nil
}

lval, rval, err = a.convertLeftRight(lval, rval)
if err != nil {
return nil, err
Expand Down

0 comments on commit 540082d

Please sign in to comment.