(stmt *ast.AlterTableSetSchemaStmt)
| 222 | } |
| 223 | |
| 224 | func (c *Catalog) alterTableSetSchema(stmt *ast.AlterTableSetSchemaStmt) error { |
| 225 | ns := stmt.Table.Schema |
| 226 | if ns == "" { |
| 227 | ns = c.DefaultSchema |
| 228 | } |
| 229 | oldSchema, err := c.getSchema(ns) |
| 230 | if err != nil { |
| 231 | return checkMissing(err, stmt.MissingOk) |
| 232 | } |
| 233 | tbl, idx, err := oldSchema.getTable(stmt.Table) |
| 234 | if err != nil { |
| 235 | return checkMissing(err, stmt.MissingOk) |
| 236 | } |
| 237 | tbl.Rel.Schema = *stmt.NewSchema |
| 238 | newSchema, err := c.getSchema(*stmt.NewSchema) |
| 239 | if err != nil { |
| 240 | return err |
| 241 | } |
| 242 | if _, _, err := newSchema.getTable(stmt.Table); err == nil { |
| 243 | return sqlerr.RelationExists(stmt.Table.Name) |
| 244 | } |
| 245 | oldSchema.Tables = append(oldSchema.Tables[:idx], oldSchema.Tables[idx+1:]...) |
| 246 | newSchema.Tables = append(newSchema.Tables, tbl) |
| 247 | return nil |
| 248 | } |
| 249 | |
| 250 | func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error { |
| 251 | ns := stmt.Name.Schema |
no test coverage detected