apache/cassandra · error · InvalidRequestException
Static column '%s' cannot be part of the PRIMARY KEY
Error message
Static column '%s' cannot be part of the PRIMARY KEY
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java:318
AbstractType<?> type = properties.type;
if (type.isMultiCell())
{
CQL3Type cqlType = properties.cqlType;
if (type.isCollection())
throw ire("Invalid non-frozen collection type %s for PRIMARY KEY column '%s'", cqlType, column);
else
throw ire("Invalid non-frozen user-defined type %s for PRIMARY KEY column '%s'", cqlType, column);
}
if (type.isCounter())
throw ire("counter type is not supported for PRIMARY KEY column '%s'", column);
if (type.referencesDuration())
throw ire("duration type is not supported for PRIMARY KEY column '%s'", column);
if (staticColumns.contains(column))
throw ire("Static column '%s' cannot be part of the PRIMARY KEY", column);
});
List<ColumnProperties> partitionKeyColumnProperties = new ArrayList<>();
List<ColumnProperties> clusteringColumnProperties = new ArrayList<>();
partitionKeyColumns.forEach(column ->
{
ColumnProperties columnProperties = columns.remove(column);
partitionKeyColumnProperties.add(columnProperties);
});
clusteringColumns.forEach(column ->
{
ColumnProperties columnProperties = columns.remove(column);
boolean reverse = !clusteringOrder.getOrDefault(column, true);
clusteringColumnProperties.add(reverse ? columnProperties.withReversedType() : columnProperties);
});
View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before CREATE TABLE t (k int, s int STATIC, PRIMARY KEY (k, s)); // after CREATE TABLE t (k int, s int STATIC, PRIMARY KEY (k));
Defensive patterns
Strategy: validation
Validate before calling
if (keyColumns.stream().anyMatch(c -> staticColumns.contains(c))) throw new IllegalArgumentException("static columns cannot be part of PRIMARY KEY"); Try / catch
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; } Prevention
- 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
When it happens
Trigger: `CREATE TABLE t (k int, s int STATIC, v int, PRIMARY KEY (k, s))` — a STATIC column listed in partition or clustering columns.
Common situations: Misunderstanding the STATIC keyword; generated DDL accidentally adding static flags to key columns; converting regular columns to STATIC after they were already keys.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- %s constraint can not be specified on a %s key column '%s'
- Static columns are only useful (and thus allowed) if the tab
- Cannot re-add previously dropped column '%s' of kind %s, inc
- Cannot drop PRIMARY KEY column %s
- Unknown column '%s' referenced in PRIMARY KEY for table '%s'
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/d98843a4841c3ff9.
Report an issue: GitHub.