Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8737,6 +8737,24 @@ from typestable`,
{3, "third row"},
},
},
{
Query: "select case when 1 then 59 + 81 / 1 end;",
Expected: []sql.Row{
{"140.0000"},
},
},
{
Query: "select case 1 when 2 then null else (6 * 2) / 1 end;",
Expected: []sql.Row{
{"12.0000"},
},
},
{
Query: "select case 1 when 1 then (6 * 2) / 1 when 2 then null else null end;",
Expected: []sql.Row{
{"12.0000"},
},
},
}

var KeylessQueries = []QueryTest{
Expand Down
16 changes: 12 additions & 4 deletions sql/expression/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ func (c *Case) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
if err != nil {
return nil, err
}
ret, _, err := t.Convert(bval)
return ret, err
// When unable to convert to the type of the case, return the original value
// A common error here is "Out of bounds value for decimal type"
if ret, _, err := t.Convert(bval); err == nil {
return ret, nil
}
return bval, nil
}
}

Expand All @@ -190,8 +194,12 @@ func (c *Case) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
if err != nil {
return nil, err
}
ret, _, err := t.Convert(val)
return ret, err
// When unable to convert to the type of the case, return the original value
// A common error here is "Out of bounds value for decimal type"
if ret, _, err := t.Convert(val); err == nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i understand, we were failing to convert a decimal to an int8 or something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we were incorrectly returning an Out of bounds value for decimal type error

return ret, nil
}
return val, nil

}

Expand Down