ValidateCreateSchema validates that CREATE SCHEMA is executed with a valid database context. In PostgreSQL, schemas exist within databases, so CREATE SCHEMA requires an active database. See: https://github.com/dolthub/doltgresql/issues/1863
( ctx *sql.Context, a *analyzer.Analyzer, n sql.Node, scope *plan.Scope, sel analyzer.RuleSelector, qFlags *sql.QueryFlags, )
| 27 | // In PostgreSQL, schemas exist within databases, so CREATE SCHEMA requires an active database. |
| 28 | // See: https://github.com/dolthub/doltgresql/issues/1863 |
| 29 | func ValidateCreateSchema( |
| 30 | ctx *sql.Context, |
| 31 | a *analyzer.Analyzer, |
| 32 | n sql.Node, |
| 33 | scope *plan.Scope, |
| 34 | sel analyzer.RuleSelector, |
| 35 | qFlags *sql.QueryFlags, |
| 36 | ) (sql.Node, transform.TreeIdentity, error) { |
| 37 | cs, ok := n.(*plan.CreateSchema) |
| 38 | if !ok { |
| 39 | return n, transform.SameTree, nil |
| 40 | } |
| 41 | |
| 42 | // Check if the current database actually has a working root. |
| 43 | // GetRootFromContext will return sql.ErrDatabaseNotFound if the database |
| 44 | // is not properly initialized. |
| 45 | _, _, err := core.GetRootFromContext(ctx) |
| 46 | if err != nil { |
| 47 | if sql.ErrDatabaseNotFound.Is(err) { |
| 48 | return nil, transform.SameTree, sql.ErrNoDatabaseSelected.New() |
| 49 | } |
| 50 | return nil, transform.SameTree, err |
| 51 | } |
| 52 | |
| 53 | return cs, transform.SameTree, nil |
| 54 | } |
nothing calls this directly
no test coverage detected