Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug for JSON values in CASE expressions #736

Merged
merged 2 commits into from
Jan 14, 2022
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
16 changes: 16 additions & 0 deletions enginetest/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3791,6 +3791,22 @@ var QueryTests = []QueryTest{
{nil},
},
},
{
Query: `SELECT CASE i WHEN 1 THEN JSON_OBJECT("a", 1) WHEN 2 THEN JSON_OBJECT("b", 2) END FROM mytable`,
Expected: []sql.Row{
{sql.MustJSON(`{"a": 1}`)},
{sql.MustJSON(`{"b": 2}`)},
{nil},
},
},
{
Query: `SELECT CASE i WHEN 1 THEN JSON_OBJECT("a", 1) ELSE JSON_OBJECT("b", 2) END FROM mytable`,
Expected: []sql.Row{
{sql.MustJSON(`{"a": 1}`)},
{sql.MustJSON(`{"b": 2}`)},
{sql.MustJSON(`{"b": 2}`)},
},
},
{
Query: "SHOW COLLATION WHERE `Collation` IN ('binary', 'utf8_general_ci', 'utf8mb4_0900_ai_ci')",
Expected: []sql.Row{
Expand Down
3 changes: 3 additions & 0 deletions sql/expression/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func combinedCaseBranchType(left, right sql.Type) sql.Type {
return sql.Int64
}
}
if sql.IsJSON(left) && sql.IsJSON(right) {
return sql.JSON
}
return sql.LongText
}

Expand Down