{"record":{"id":"670f5c1d202cc380","repo":"vitessio/vitess","slug":"error-parsing-vschema-statement-s-v","errorCode":null,"errorMessage":"error parsing vschema statement `%s`: %v","messagePattern":"error parsing vschema statement `(.+?)`: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/vtctl.go","lineNumber":3375,"sourceCode":"\t\treturn errors.New(\"only one of the --sql, --sql_file, --vschema, or --vschema_file flags may be specified when calling the ApplyVSchema command\")\n\t}\n\n\tif !sqlMode && !jsonMode {\n\t\treturn errors.New(\"one of the --sql, --sql_file, --vschema, or --vschema_file flags must be specified when calling the ApplyVSchema command\")\n\t}\n\n\tif sqlMode {\n\t\tif *sqlFile != \"\" {\n\t\t\tsqlBytes, err := os.ReadFile(*sqlFile)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\t*sql = string(sqlBytes)\n\t\t}\n\n\t\tstmt, err := wr.SQLParser().Parse(*sql)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error parsing vschema statement `%s`: %v\", *sql, err)\n\t\t}\n\t\tddl, ok := stmt.(*sqlparser.AlterVschema)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"error parsing vschema statement `%s`: not a ddl statement\", *sql)\n\t\t}\n\n\t\tksvs, err = topotools.ApplyVSchemaDDL(ctx, keyspace, wr.TopoServer(), ddl)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {\n\t\t// json mode\n\t\tvar schema []byte\n\t\tif *vschemaFile != \"\" {\n\t\t\tvar err error\n\t\t\tschema, err = os.ReadFile(*vschemaFile)\n\t\t\tif err != nil {\n\t\t\t\treturn err","sourceCodeStart":3357,"sourceCodeEnd":3393,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/vtctl.go#L3357-L3393","documentation":"The RebuildKeyspace/VSchema command failed to parse the user-supplied vschema SQL statement with the SQL parser. The raw statement is embedded in the error along with the parser error. This is a client-side parse validation before any topo mutation happens.","triggerScenarios":"Running `vtctldclient RebuildVSchemaGraph`/ApplyVSchema with an `*sql` string that is not valid vschema DDL syntax (e.g. malformed `ALTER VSCHEMA ADD TABLE ...`).","commonSituations":"Typo in vindex definition JSON, missing semicolons/quotes, passing a plain DDL statement instead of an AlterVschema, JSON with special characters not escaped in shell.","solutions":["Validate the vschema statement syntax locally with a SQL parser or `vtctldclient` dry run before applying","Check the embedded `%v` parser error for the exact token/position that failed","If embedding JSON, ensure it is properly quoted/escaped in the shell or file"],"exampleFix":"// before\nsql := `ALTER VSCHEMA ADD TABLE test`  // missing vindex spec, parse fails\n// after\nsql := `ALTER VSCHEMA ADD TABLE test vindex hash`","handlingStrategy":"validation","validationCode":"stmt, err := sqlparser.Parse(sql)\nif err != nil {\n\treturn fmt.Errorf(\"invalid vschema statement %q: %v\", sql, err)\n}\nif _, ok := stmt.(*sqlparser.AlterVschema); !ok {\n\treturn fmt.Errorf(\"must be ALTER VSCHEMA statement\")\n}","typeGuard":"func isAlterVschema(stmt sqlparser.Statement) bool {\n\t_, ok := stmt.(*sqlparser.AlterVschema)\n\treturn ok\n}","tryCatchPattern":"if err := applyVSchema(sql); err != nil {\n\tif strings.Contains(err.Error(), \"error parsing vschema statement\") {\n\t\treturn fmt.Errorf(\"check vschema syntax: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Keep vschema statements in version-controlled files and lint them in CI","Test the vschema against a scratch keyspace before applying to production","Escape quotes when embedding vschema in shell commands"],"tags":["vtctl","vschema","sqlparser","go"],"backgroundTag":"sql-parse-error","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}