Skip to content

Commit 0d9045e

Browse files
committed
add fallback for create schema
1 parent 1b9f80d commit 0d9045e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sql/rowexec/ddl.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,17 @@ 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 behavior
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
408412
if database == "" {
409-
return nil, sql.ErrNoDatabaseSelected.New()
413+
return b.buildCreateDB(ctx, &plan.CreateDB{
414+
Catalog: n.Catalog,
415+
DbName: n.DbName,
416+
IfNotExists: n.IfNotExists,
417+
Collation: n.Collation,
418+
}, row)
410419
}
411420

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

0 commit comments

Comments
 (0)