{"record":{"id":"9b5e4b555e29eeb3","repo":"apache/cassandra","slug":"duplicate-column-s-in-primary-key-clause-for-ta","errorCode":null,"errorMessage":"Duplicate column '%s' in PRIMARY KEY clause for table '%s'","messagePattern":"Duplicate column '(.+?)' in PRIMARY KEY clause for table '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":299,"sourceCode":"                    if (field.isMultiCell())\n                        throw ire(\"Non-frozen UDTs with nested non-frozen collections are not supported\");\n                });\n            }\n        });\n\n        /*\n         * Deal with PRIMARY KEY columns\n         */\n\n        HashSet<ColumnIdentifier> primaryKeyColumns = new HashSet<>();\n        concat(partitionKeyColumns, clusteringColumns).forEach(column ->\n        {\n            ColumnProperties properties = columns.get(column);\n            if (null == properties)\n                throw ire(\"Unknown column '%s' referenced in PRIMARY KEY for table '%s'\", column, tableName);\n\n            if (!primaryKeyColumns.add(column))\n                throw ire(\"Duplicate column '%s' in PRIMARY KEY clause for table '%s'\", column, tableName);\n\n            AbstractType<?> type = properties.type;\n            if (type.isMultiCell())\n            {\n                CQL3Type cqlType = properties.cqlType;\n                if (type.isCollection())\n                    throw ire(\"Invalid non-frozen collection type %s for PRIMARY KEY column '%s'\", cqlType, column);\n                else\n                    throw ire(\"Invalid non-frozen user-defined type %s for PRIMARY KEY column '%s'\", cqlType, column);\n            }\n\n            if (type.isCounter())\n                throw ire(\"counter type is not supported for PRIMARY KEY column '%s'\", column);\n\n            if (type.referencesDuration())\n                throw ire(\"duration type is not supported for PRIMARY KEY column '%s'\", column);\n\n            if (staticColumns.contains(column))","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L281-L317","documentation":"CreateTableStatement.builder PRIMARY KEY handling: the same column appears more than once across partition key and clustering column lists, detected via a HashSet add; duplicates in PRIMARY KEY are rejected.","triggerScenarios":"`CREATE TABLE t (k int, v int, PRIMARY KEY ((k, k)))` or a column listed both as partition key and clustering column.","commonSituations":"Hand-editing composite primary keys and duplicating a component; DDL generators concatenating partition and clustering lists incorrectly.","solutions":["Remove the duplicate occurrence so each column appears once in the PRIMARY KEY","If a column should be both partition and clustering in effect, reconsider the key design — a column cannot repeat"],"exampleFix":"// before\nCREATE TABLE t (k int, v int, PRIMARY KEY ((k, k), v));\n// after\nCREATE TABLE t (k int, v int, PRIMARY KEY ((k, v)));","handlingStrategy":"validation","validationCode":"List<String> seen = new ArrayList<>(); for (String c : allKeyColumns) { if (!seen.add(c)) throw new IllegalArgumentException(\"Duplicate column in PRIMARY KEY: \" + c); }","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"Duplicate column\") && e.getMessage().contains(\"PRIMARY KEY\")) { /* deduplicate the key clause */ } else throw e; }","preventionTips":["Build primary key lists programmatically with de-duplication","Review hand-edited composite keys for repeated components","Validate DDL with a parser before execution"],"tags":["cql","schema","primary-key"],"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-14T16:17:12.679Z"}