{"record":{"id":"31ec95f05a9a7190","repo":"apache/cassandra","slug":"duplicate-column-s-declaration-for-table-s","errorCode":null,"errorMessage":"Duplicate column '%s' declaration for table '%s'","messagePattern":"Duplicate column '(.+?)' declaration for table '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":626,"sourceCode":"            name.setKeyspace(keyspace, true);\n            return this;\n        }\n\n        public Raw table(String table)\n        {\n            name.setName(table, true);\n            return this;\n        }\n\n        public String table()\n        {\n            return name.getName();\n        }\n\n        public void addColumn(ColumnIdentifier column, CQL3Type.Raw type, boolean isStatic, boolean isNotNull, ColumnMask.Raw mask, ColumnConstraints.Raw constraints)\n        {\n            if (null != rawColumns.put(column, new ColumnProperties.Raw(type, mask)))\n                throw ire(\"Duplicate column '%s' declaration for table '%s'\", column, name);\n\n            if (isStatic)\n                staticColumns.add(column);\n\n            ColumnConstraints preparedConstraints = constraints == null ? ColumnConstraints.NO_OP : constraints.prepare(column);\n\n            if (isNotNull)\n            {\n                 if (preparedConstraints.containsNotNullConstraint())\n                     throw ire(\"Duplicate definition of NOT NULL constraint\");\n\n                List<ColumnConstraint<?>> checkConstraints = new ArrayList<>(preparedConstraints.getConstraints());\n                checkConstraints.add(new UnaryFunctionColumnConstraint(new NotNullConstraint()));\n                preparedConstraints = new ColumnConstraints(checkConstraints);\n                preparedConstraints.setColumnName(column);\n            }\n\n            columnConstraints.put(column, preparedConstraints);","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L608-L644","documentation":"The same column name appears more than once in the CREATE TABLE column list. The raw builder stores columns in a map keyed by ColumnIdentifier; if put() returns a previous value, the column was declared twice and the statement is rejected.","triggerScenarios":"CREATE TABLE t (a int, a text); — the second addColumn call for an already-declared identifier throws.","commonSituations":"Copy-pasted column definitions; generated DDL concatenating column lists from multiple sources; case-insensitive collisions if quoting differs (e.g. A and \"A\" resolve to the same identifier).","solutions":["Remove the duplicate column declaration, keeping only one type per name","Rename one of the colliding columns","If identifiers are quoted, ensure casing does not collapse two names into the same identifier"],"exampleFix":"// before\nCREATE TABLE t (a int, a text, PRIMARY KEY (a));\n// after\nCREATE TABLE t (a int, b text, PRIMARY KEY (a));","handlingStrategy":"validation","validationCode":"const names = cols.map(c => c.name.toLowerCase());\nconst dup = names.find((n, i) => names.indexOf(n) !== i);\nif (dup) throw new Error(`Duplicate column: ${dup}`);","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (/Duplicate column/.test(e.message)) { /* de-duplicate the column list and retry */ } else throw e; }","preventionTips":["De-duplicate column names (case-insensitively) before generating DDL","Avoid concatenating column lists from multiple schema fragments","Be careful with quoted identifiers changing casing"],"tags":["cql","schema","duplicate-column"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}