{"record":{"id":"6c145068f25a9f5d","repo":"vitessio/vitess","slug":"unrecognized-statement-s-6c1450","errorCode":null,"errorMessage":"unrecognized statement: %s","messagePattern":"unrecognized statement: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/materializer.go","lineNumber":1362,"sourceCode":"\t\t}\n\t\tfor _, ts := range mz.ms.TableSettings {\n\t\t\trule := &binlogdatapb.Rule{\n\t\t\t\tMatch: ts.TargetTable,\n\t\t\t}\n\n\t\t\tif ts.SourceExpression == \"\" {\n\t\t\t\tbls.Filter.Rules = append(bls.Filter.Rules, rule)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Validate non-empty query.\n\t\t\tstmt, err := mz.wr.env.Parser().Parse(ts.SourceExpression)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\tsel, ok := stmt.(*sqlparser.Select)\n\t\t\tif !ok {\n\t\t\t\treturn \"\", fmt.Errorf(\"unrecognized statement: %s\", ts.SourceExpression)\n\t\t\t}\n\t\t\tfilter := ts.SourceExpression\n\n\t\t\tif !keyRangesEqual && mz.targetVSchema.Keyspace.Sharded && mz.targetVSchema.Tables[ts.TargetTable].Type != vindexes.TypeReference {\n\t\t\t\tcv, err := vindexes.FindBestColVindex(mz.targetVSchema.Tables[ts.TargetTable])\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn \"\", err\n\t\t\t\t}\n\t\t\t\tmappedCols := make([]*sqlparser.ColName, 0, len(cv.Columns))\n\t\t\t\tfor _, col := range cv.Columns {\n\t\t\t\t\tcolName, err := matchColInSelect(col, sel)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn \"\", err\n\t\t\t\t\t}\n\t\t\t\t\tmappedCols = append(mappedCols, colName)\n\t\t\t\t}\n\t\t\t\tsubExprs := make([]sqlparser.Expr, 0, len(mappedCols)+2)\n\t\t\t\tfor _, mappedCol := range mappedCols {","sourceCodeStart":1344,"sourceCodeEnd":1380,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/materializer.go#L1344-L1380","documentation":"generateInserts parses each TableSettings SourceExpression expecting a plain SELECT statement to use as the copy filter. If the statement parses but is not a *sqlparser.Select (e.g. INSERT, UPDATE, SET, or another statement type), it fails with 'unrecognized statement'.","triggerScenarios":"MaterializeSettings.TableSettings.SourceExpression set to a non-SELECT statement, or to an unparsable-in-select-position construct; programmatic use of MoveTables/Materialize APIs with hand-written SourceExpression values.","commonSituations":"Users pasting full `INSERT INTO ... SELECT ...` or `SELECT ... INTO` statements into filter/SourceExpression config; using comments or multiple statements; older configs that stored filters in a different format.","solutions":["Change SourceExpression to a single plain SELECT statement, e.g. `select * from t where col = 'x'`","Remove any leading/trailing statements, semicolons, or non-select clauses","Verify with the sqlparser or by running the select manually on the source keyspace"],"exampleFix":"// before\n{\"sourceExpression\":\"insert into t select * from s\"}\n// after\n{\"sourceExpression\":\"select * from s\"}","handlingStrategy":"validation","validationCode":"stmt, err := parser.Parse(sourceExpression)\nif err != nil { return err }\nif _, ok := stmt.(*sqlparser.Select); !ok {\n    return fmt.Errorf(\"SourceExpression must be a SELECT, got %T\", stmt)\n}","typeGuard":"func isSelectStmt(p *sqlparser.Parser, expr string) bool {\n    s, err := p.Parse(expr)\n    _, ok := s.(*sqlparser.Select)\n    return err == nil && ok\n}","tryCatchPattern":"if err := workflow.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"unrecognized statement\") {\n        // fix SourceExpression to a plain SELECT and retry\n    }\n}","preventionTips":["Only ever put plain SELECT statements in SourceExpression/filter","Validate expressions with the parser before creating the workflow"],"tags":["vitess","wrangler","sqlparser","validation"],"backgroundTag":"invalid-source-expression","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}