{"record":{"id":"d98843a4841c3ff9","repo":"apache/cassandra","slug":"static-column-s-cannot-be-part-of-the-primary-k","errorCode":null,"errorMessage":"Static column '%s' cannot be part of the PRIMARY KEY","messagePattern":"Static column '(.+?)' cannot be part of the PRIMARY KEY","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":318,"sourceCode":"\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))\n                throw ire(\"Static column '%s' cannot be part of the PRIMARY KEY\", column);\n        });\n\n        List<ColumnProperties> partitionKeyColumnProperties = new ArrayList<>();\n        List<ColumnProperties> clusteringColumnProperties = new ArrayList<>();\n\n        partitionKeyColumns.forEach(column ->\n        {\n            ColumnProperties columnProperties = columns.remove(column);\n            partitionKeyColumnProperties.add(columnProperties);\n        });\n\n        clusteringColumns.forEach(column ->\n        {\n            ColumnProperties columnProperties = columns.remove(column);\n            boolean reverse = !clusteringOrder.getOrDefault(column, true);\n            clusteringColumnProperties.add(reverse ? columnProperties.withReversedType() : columnProperties);\n        });\n","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L300-L336","documentation":"Thrown from CreateTableStatement's builder while validating the PRIMARY KEY clause when one of the referenced columns was declared STATIC. Static columns hold a single value per partition and therefore cannot contribute to partition or clustering identity, so mixing a static column into the PRIMARY KEY is rejected.","triggerScenarios":"`CREATE TABLE t (k int, s int STATIC, v int, PRIMARY KEY (k, s))` — a STATIC column listed in partition or clustering columns.","commonSituations":"Misunderstanding the STATIC keyword; generated DDL accidentally adding static flags to key columns; converting regular columns to STATIC after they were already keys.","solutions":["Remove the STATIC keyword from the column used in the PRIMARY KEY","Remove the column from the PRIMARY KEY if it is genuinely intended to be partition-static","Introduce a separate static column for partition-level data"],"exampleFix":"// before\nCREATE TABLE t (k int, s int STATIC, PRIMARY KEY (k, s));\n// after\nCREATE TABLE t (k int, s int STATIC, PRIMARY KEY (k));","handlingStrategy":"validation","validationCode":"if (keyColumns.stream().anyMatch(c -> staticColumns.contains(c))) throw new IllegalArgumentException(\"static columns cannot be part of PRIMARY KEY\");","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"Static column\") && e.getMessage().contains(\"PRIMARY KEY\")) { /* drop STATIC from the key column or remove it from the key */ } else throw e; }","preventionTips":["Apply STATIC only to regular (non-key) columns","Keep static and key column sets disjoint in schema generators","Review any schema migration that adds STATIC to existing columns"],"tags":["cql","static-column","primary-key","schema"],"backgroundTag":"invalid-argument-value","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"}