{"record":{"id":"e3ed458447b1729d","repo":"vitessio/vitess","slug":"expected-a-create-table-statement","errorCode":null,"errorMessage":"expected a CREATE TABLE statement","messagePattern":"expected a CREATE TABLE statement","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schemadiff/errors.go","lineNumber":33,"sourceCode":"*/\n\npackage schemadiff\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n\n\t\"vitess.io/vitess/go/sqlescape\"\n\t\"vitess.io/vitess/go/vt/sqlparser\"\n)\n\nvar (\n\tErrEntityTypeMismatch             = errors.New(\"mismatched entity type\")\n\tErrStrictIndexOrderingUnsupported = errors.New(\"strict index ordering is unsupported\")\n\tErrUnexpectedDiffAction           = errors.New(\"unexpected diff action\")\n\tErrUnexpectedTableSpec            = errors.New(\"unexpected table spec\")\n\tErrExpectedCreateTable            = errors.New(\"expected a CREATE TABLE statement\")\n\tErrExpectedCreateView             = errors.New(\"expected a CREATE VIEW statement\")\n)\n\ntype ImpossibleApplyDiffOrderError struct {\n\tUnorderedDiffs   []EntityDiff\n\tConflictingDiffs []EntityDiff\n}\n\nfunc (e *ImpossibleApplyDiffOrderError) Error() string {\n\tvar b strings.Builder\n\tconflictingStatements := e.ConflictingStatements()\n\tfmt.Fprintf(&b, \"no valid applicable order for diffs. %d diffs found conflicting:\", len(conflictingStatements))\n\tfor _, s := range conflictingStatements {\n\t\tb.WriteString(\"\\n\")\n\t\tb.WriteString(s)\n\t}\n\treturn b.String()\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schemadiff/errors.go#L15-L51","documentation":"ErrExpectedCreateTable is returned when code requires a CREATE TABLE statement but receives a different statement type. Shared by DiffCreateTablesQueries, NewCreateTableEntityFromSQL, NewCreateViewEntityFromSQL, and getCreateTableStatement when statement-type expectations are violated.","triggerScenarios":"Passing a CREATE VIEW / ALTER / non-DDL statement to NewCreateTableEntityFromSQL or getCreateTableStatement; DiffCreateTablesQueries receiving entity diffs whose statements are not CREATE TABLE.","commonSituations":"Mixing table and view DDL files when loading a keyspace schema; off-by-one slicing of SQL files that concatenates statements incorrectly.","solutions":["Pass only CREATE TABLE statements to table-entity APIs","Use NewCreateViewEntityFromSQL / DiffCreateViewsQueries for view statements","Verify the SQL being loaded actually parses as CREATE TABLE before calling schemadiff"],"exampleFix":"// before\nentity, err := schemadiff.NewCreateTableEntityFromSQL(\"CREATE VIEW v1 AS SELECT 1\") // expected a CREATE TABLE statement\n// after\nentity, err := schemadiff.NewCreateViewEntityFromSQL(\"CREATE VIEW v1 AS SELECT 1\")","handlingStrategy":"type-guard","validationCode":"stmt, err := sqlparser.Parse(ddl)\nif _, ok := stmt.(*sqlparser.CreateTable); !ok {\n\treturn fmt.Errorf(\"not a CREATE TABLE: %T\", stmt)\n}","typeGuard":"func isCreateTable(stmt sqlparser.Statement) bool {\n\t_, ok := stmt.(*sqlparser.CreateTable)\n\treturn ok\n}","tryCatchPattern":"if err != nil {\n\tif errors.Is(err, schemadiff.ErrExpectedCreateTable) {\n\t\t// route to view handling or reject input\n\t}\n}","preventionTips":["Separate table and view DDL files","Type-assert parsed statements before constructing entities","Use the *View constructors for view statements"],"tags":["schemadiff","ddl","statement-type"],"backgroundTag":"unexpected-statement-type","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}