{"record":{"id":"0569baf6093fcceb","repo":"vitessio/vitess","slug":"source-and-target-table-names-must-match-for-copyi-0569ba","errorCode":null,"errorMessage":"source and target table names must match for copying schema: %v vs %v","messagePattern":"source and target table names must match for copying schema: (.+?) vs (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/materializer.go","lineNumber":1212,"sourceCode":"\t\t\t\t// and we have found use cases where user just has a replica (no primary) in the source keyspace\n\t\t\t\tsourceDDLs, err = mz.getSourceTableDDLs(ctx)\n\t\t\t}\n\t\t\tmu.Unlock()\n\t\t\tif err != nil {\n\t\t\t\tlog.Error(\"Error getting DDLs of source tables: \" + err.Error())\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tcreateDDL := ts.CreateDdl\n\t\t\tif createDDL == createDDLAsCopy || createDDL == createDDLAsCopyDropConstraint || createDDL == createDDLAsCopyDropForeignKeys {\n\t\t\t\tif ts.SourceExpression != \"\" {\n\t\t\t\t\t// Check for table if non-empty SourceExpression.\n\t\t\t\t\tsourceTableName, err := mz.wr.env.Parser().TableFromStatement(ts.SourceExpression)\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\tif sourceTableName.Name.String() != ts.TargetTable {\n\t\t\t\t\t\treturn fmt.Errorf(\"source and target table names must match for copying schema: %v vs %v\", sqlparser.String(sourceTableName), ts.TargetTable)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tddl, ok := sourceDDLs[ts.TargetTable]\n\t\t\t\tif !ok {\n\t\t\t\t\treturn fmt.Errorf(\"source table %v does not exist\", ts.TargetTable)\n\t\t\t\t}\n\n\t\t\t\tif createDDL == createDDLAsCopyDropConstraint {\n\t\t\t\t\tstrippedDDL, err := stripTableConstraints(ddl, mz.wr.env.Parser())\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\n\t\t\t\t\tddl = strippedDDL\n\t\t\t\t}\n\n\t\t\t\tif createDDL == createDDLAsCopyDropForeignKeys {","sourceCodeStart":1194,"sourceCodeEnd":1230,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/materializer.go#L1194-L1230","documentation":"When CreateDdl is 'copy'-style and the TableSettings has a non-empty SourceExpression, the materializer verifies the SELECT's source table name equals the target table name, because schema copy assumes source and target are the same table. A mismatch (e.g. a WHERE/join or renamed table) makes copying ambiguous and fails.","triggerScenarios":"MaterializeSettings.TableSettings with CreateDdl=copy and a SourceExpression whose parsed FROM table differs from TargetTable, e.g. `select ... from src_table` with TargetTable `dst_table`, or a select against a joined/derived table.","commonSituations":"Users configuring a materialized view (filter/transform) while accidentally leaving create-ddl='copy' from a previous same-name MoveTables config; copy-paste of TableSettings across workflows with renamed tables.","solutions":["Rename TargetTable to match the source table name in the SourceExpression","Or change CreateDdl to an explicit CREATE TABLE string (not 'copy') when the target table name intentionally differs","Or empty the SourceExpression if schema-only copy was intended"],"exampleFix":"// before (MaterializeSettings in json)\n{\"targetTable\":\"dst\",\"sourceExpression\":\"select * from src\",\"createDdl\":\"copy\"}\n// after: either match names or give explicit DDL\n{\"targetTable\":\"src\",\"sourceExpression\":\"select * from src where id>0\",\"createDdl\":\"copy\"}\n{\"targetTable\":\"dst\",\"sourceExpression\":\"select * from src\",\"createDdl\":\"CREATE TABLE dst (...)\"}","handlingStrategy":"validation","validationCode":"for _, ts := range settings.TableSettings {\n    if ts.CreateDdl == \"copy\" && ts.SourceExpression != \"\" {\n        t, err := parser.TableFromStatement(ts.SourceExpression)\n        if err != nil { return err }\n        if t.Name.String() != ts.TargetTable {\n            return fmt.Errorf(\"create-ddl=copy requires matching names: %s vs %s\", t.Name, ts.TargetTable)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use explicit CREATE TABLE DDL when target name differs from source","Keep rename-style materializations out of 'copy' mode","Lint MaterializeSettings before submitting workflows"],"tags":["vitess","wrangler","schema-copy","validation"],"backgroundTag":"table-name-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}