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
54 changes: 54 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,60 @@ type ScriptTestAssertion struct {
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
// the tests.
var ScriptTests = []ScriptTest{
{
// https://github.com/dolthub/go-mysql-server/issues/3216
Name: "UNION ALL with BLOB columns",
SetUpScript: []string{
"CREATE TABLE a(name VARCHAR(255), data BLOB)",
"CREATE TABLE b(name VARCHAR(255), data BLOB)",
"INSERT INTO a VALUES ('a-data', UNHEX('deadbeef'))",
"INSERT INTO b VALUES ('b-nodata', NULL)",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT name, data FROM a UNION ALL SELECT name, data FROM b",
Expected: []sql.Row{
{"a-data", []byte{0xde, 0xad, 0xbe, 0xef}},
{"b-nodata", nil},
},
},
{
Query: "SELECT name, HEX(data) as data_hex FROM a UNION ALL SELECT name, HEX(data) as data_hex FROM b",
Expected: []sql.Row{
{"a-data", "DEADBEEF"},
{"b-nodata", nil},
},
},
{
Query: "SELECT name, data FROM a UNION ALL SELECT name, NULL FROM b",
Expected: []sql.Row{
{"a-data", []byte{0xde, 0xad, 0xbe, 0xef}},
{"b-nodata", nil},
},
},
{
Query: "SELECT name, HEX(data) as data_hex FROM a UNION ALL SELECT name, HEX(NULL) as data_hex FROM b",
Expected: []sql.Row{
{"a-data", "DEADBEEF"},
{"b-nodata", nil},
},
},
{
Query: "SELECT name, data FROM a UNION ALL SELECT name, UNHEX('') FROM b",
Expected: []sql.Row{
{"a-data", []byte{0xde, 0xad, 0xbe, 0xef}},
{"b-nodata", []byte{}},
},
},
{
Query: "SELECT name, HEX(data) as data_hex FROM a UNION ALL SELECT name, HEX(UNHEX('')) as data_hex FROM b",
Expected: []sql.Row{
{"a-data", "DEADBEEF"},
{"b-nodata", ""},
},
},
},
},
{
// https://github.com/dolthub/dolt/issues/9836
Skip: true,
Expand Down
4 changes: 4 additions & 0 deletions sql/expression/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func GetConvertToType(l, r sql.Type) string {
}

if !types.IsNumber(l) || !types.IsNumber(r) {
// Special handling for BLOB types - preserve binary data
if types.IsBlobType(l) || types.IsBlobType(r) {
return ConvertToBinary
}
return ConvertToChar
}

Expand Down
Loading