{"record":{"id":"195ca813c4bb2a90","repo":"apache/cassandra","slug":"multiple-primary-key-specified-for-table-s-exa","errorCode":null,"errorMessage":"Multiple PRIMARY KEY specified for table '%s' (exactly one required)","messagePattern":"Multiple PRIMARY KEY specified for table '(.+?)' \\(exactly one required\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":665,"sourceCode":"        public void addColumn(ColumnIdentifier column, CQL3Type.Raw type, boolean isStatic, ColumnMask.Raw mask, ColumnConstraints.Raw constraints)\n        {\n            addColumn(column, type, isStatic, false, mask, constraints);\n        }\n\n        public void setCompactStorage()\n        {\n            useCompactStorage = true;\n        }\n\n        public void setPartitionKeyColumn(ColumnIdentifier column)\n        {\n            setPartitionKeyColumns(Collections.singletonList(column));\n        }\n\n        public void setPartitionKeyColumns(List<ColumnIdentifier> columns)\n        {\n            if (null != partitionKeyColumns)\n                throw ire(\"Multiple PRIMARY KEY specified for table '%s' (exactly one required)\", name);\n\n            partitionKeyColumns = columns;\n        }\n\n        public void markClusteringColumn(ColumnIdentifier column)\n        {\n            clusteringColumns.add(column);\n        }\n\n        public void extendClusteringOrder(ColumnIdentifier column, boolean ascending)\n        {\n            if (null != clusteringOrder.put(column, ascending))\n                throw ire(\"Duplicate column '%s' in CLUSTERING ORDER BY clause for table '%s'\", column, name);\n        }\n    }\n\n    /**\n     * Class encapsulating the properties of a column, which are its type and mask.","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L647-L683","documentation":"The PRIMARY KEY was specified more than once for the same CREATE TABLE statement. The raw builder's setPartitionKeyColumns throws if partitionKeyColumns is already non-null, because exactly one PRIMARY KEY definition is allowed.","triggerScenarios":"Calling PRIMARY KEY (a) inline on a column and also adding a trailing PRIMARY KEY (a) clause; calling setPartitionKeyColumns twice on the Raw builder; calling setPartitionKeyColumn (singular helper) after an explicit PRIMARY KEY clause.","commonSituations":"Mixing inline key syntax (a int PRIMARY KEY) with a separate PRIMARY KEY clause in generated DDL; programmatic schema assembly combining fragments that each set the partition key.","solutions":["Specify the PRIMARY KEY exactly once — either inline on one column or as a trailing PRIMARY KEY (...) clause, not both","In builder code, ensure only one code path calls setPartitionKeyColumns"],"exampleFix":"// before\nCREATE TABLE t (a int PRIMARY KEY, b text, PRIMARY KEY (a));\n// after\nCREATE TABLE t (a int PRIMARY KEY, b text);","handlingStrategy":"validation","validationCode":"const pkCount = (ddl.match(/PRIMARY\\s+KEY/gi) || []).length + (ddl.match(/\\b\\w+\\s+\\w+\\s+PRIMARY\\s+KEY\\b/gi) || []).length;\nif (pkCount > 1) throw new Error('At most one PRIMARY KEY clause allowed');","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (/Multiple PRIMARY KEY/.test(e.message)) { /* remove the redundant PRIMARY KEY clause and retry */ } else throw e; }","preventionTips":["Use either inline column PRIMARY KEY or a trailing PRIMARY KEY (...) clause, never both","In builders, centralize partition-key assignment in one code path","Lint generated DDL for duplicate PRIMARY KEY clauses"],"tags":["cql","schema","primary-key","duplicate"],"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"}