Skip to content

Commit cb8cb6a

Browse files
committed
Merge branch 'main' of https://github.com/dolthub/go-mysql-server into angela/groupby
2 parents fcd8ea2 + 1e27be8 commit cb8cb6a

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

enginetest/queries/script_queries.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13519,6 +13519,52 @@ var BrokenScriptTests = []ScriptTest{
1351913519
}
1352013520

1352113521
var CreateDatabaseScripts = []ScriptTest{
13522+
{
13523+
// https://github.com/dolthub/dolt/pull/9830
13524+
Name: "CREATE SCHEMA without database selection falls back to CREATE DATABASE",
13525+
SetUpScript: []string{
13526+
"CREATE DATABASE tmp",
13527+
"USE tmp",
13528+
},
13529+
Dialect: "mysql",
13530+
Assertions: []ScriptTestAssertion{
13531+
{
13532+
Query: "DROP DATABASE tmp",
13533+
},
13534+
{
13535+
Query: "CREATE SCHEMA NewDatabase",
13536+
Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}},
13537+
},
13538+
{
13539+
Query: "SHOW DATABASES",
13540+
Expected: []sql.Row{{"NewDatabase"}, {"information_schema"}, {"mydb"}, {"mysql"}},
13541+
},
13542+
{
13543+
Query: "USE NewDatabase",
13544+
Expected: []sql.Row{},
13545+
},
13546+
{
13547+
Query: "SELECT DATABASE()",
13548+
Expected: []sql.Row{{"NewDatabase"}},
13549+
},
13550+
{
13551+
Query: "CREATE TABLE test_table (id INT PRIMARY KEY)",
13552+
Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}},
13553+
},
13554+
{
13555+
Query: "SHOW TABLES",
13556+
Expected: []sql.Row{{"test_table"}},
13557+
},
13558+
{
13559+
Query: "USE mydb",
13560+
Expected: []sql.Row{},
13561+
},
13562+
{
13563+
Query: "DROP DATABASE NewDatabase",
13564+
Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}},
13565+
},
13566+
},
13567+
},
1352213568
{
1352313569
Name: "CREATE DATABASE and create table",
1352413570
Assertions: []ScriptTestAssertion{

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250915221346-753c44800850
9+
github.com/dolthub/vitess v0.0.0-20250918181259-ed0e1c5cb192
1010
github.com/go-sql-driver/mysql v1.9.3
1111
github.com/gocraft/dbr/v2 v2.7.2
1212
github.com/google/uuid v1.3.0
@@ -41,4 +41,4 @@ require (
4141
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
4242
)
4343

44-
go 1.24.6
44+
go 1.25

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
1818
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
1919
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
2020
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
21-
github.com/dolthub/vitess v0.0.0-20250915221346-753c44800850 h1:QXkIRTquxaGUgKVHnKZxU+ikARdszUUDU6C9B/76+a0=
22-
github.com/dolthub/vitess v0.0.0-20250915221346-753c44800850/go.mod h1:tV3BrIVyDWVkkYy8dKt2o6hjJ89cHb5opY5FpCyhncQ=
21+
github.com/dolthub/vitess v0.0.0-20250918181259-ed0e1c5cb192 h1:s7Ghoy+x+C/spSjM5/w9MoMIIeXNcBY/fI2oHxWajLM=
22+
github.com/dolthub/vitess v0.0.0-20250918181259-ed0e1c5cb192/go.mod h1:8pvvk5OLaLN9LLxghyczUapn/97l+mBgIb10qC1LG84=
2323
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
2424
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
2525
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

sql/rowexec/ddl.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,18 @@ func (b *BaseBuilder) buildCreateDB(ctx *sql.Context, n *plan.CreateDB, row sql.
405405

406406
func (b *BaseBuilder) buildCreateSchema(ctx *sql.Context, n *plan.CreateSchema, row sql.Row) (sql.RowIter, error) {
407407
database := ctx.GetCurrentDatabase()
408+
409+
// If no database is selected, first try to fall back to CREATE DATABASE
410+
// since CREATE SCHEMA is a synonym for CREATE DATABASE in MySQL
411+
// https://dev.mysql.com/doc/refman/8.4/en/create-database.html
412+
// TODO: For PostgreSQL, return an error if no database is selected.
408413
if database == "" {
409-
return nil, sql.ErrNoDatabaseSelected.New()
414+
return b.buildCreateDB(ctx, &plan.CreateDB{
415+
Catalog: n.Catalog,
416+
DbName: n.DbName,
417+
IfNotExists: n.IfNotExists,
418+
Collation: n.Collation,
419+
}, row)
410420
}
411421

412422
db, err := n.Catalog.Database(ctx, database)

0 commit comments

Comments
 (0)