{"record":{"id":"ad93922bf4d69b44","repo":"vitessio/vitess","slug":"expected-a-create-view-statement","errorCode":null,"errorMessage":"expected a CREATE VIEW statement","messagePattern":"expected a CREATE VIEW statement","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schemadiff/errors.go","lineNumber":34,"sourceCode":"\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}\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schemadiff/errors.go#L16-L52","documentation":"ErrExpectedCreateView is returned by DiffCreateViewsQueries when a view entity's statement is not a CREATE VIEW statement. View diffing only operates on CREATE VIEW definitions, so any other statement type in the entity list triggers this error.","triggerScenarios":"Calling DiffCreateViewsQueries with entities built from table DDL or ALTER statements instead of CREATE VIEW statements.","commonSituations":"Schema-loading code that puts all DDL (tables + views) through the view diff path; renamed statements (e.g. CREATE OR REPLACE VIEW variants) that no longer parse as plain CREATE VIEW in the code path.","solutions":["Filter entity lists so only CREATE VIEW entities go to DiffCreateViewsQueries","Use DiffCreateTablesQueries for table entities","Recreate view entities with NewCreateViewEntityFromSQL from the original CREATE VIEW text"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"stmt, err := sqlparser.Parse(ddl)\nct, ok := stmt.(*sqlparser.CreateTable)\nif ok && ct.ViewSpec != nil { /* it is a view; use view APIs */ }","typeGuard":"func isCreateView(e schemadiff.Entity) bool {\n\t_, ok := e.(*schemadiff.CreateViewEntity)\n\treturn ok\n}","tryCatchPattern":"if err != nil {\n\tif errors.Is(err, schemadiff.ErrExpectedCreateView) {\n\t\t// route to table diffing instead\n\t}\n}","preventionTips":["Filter entities by type before calling DiffCreateViewsQueries","Construct view entities via NewCreateViewEntityFromSQL only","Keep view inventory separate from table inventory"],"tags":["schemadiff","view","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"}