{"record":{"id":"4f9fe8dfbfdb5381","repo":"apache/cassandra","slug":"static-columns-are-only-useful-and-thus-allowed-4f9fe8","errorCode":null,"errorMessage":"Static columns are only useful (and thus allowed) if the table has at least one clustering column","messagePattern":"Static columns are only useful \\(and thus allowed\\) if the table has at least one clustering column","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java","lineNumber":368,"sourceCode":"            {\n                if (clusteringOrder.containsKey(c))\n                    throw ire(\"The order of columns in the CLUSTERING ORDER directive must match that of the clustering columns (%s must appear before %s)\", c, id);\n                else\n                    throw ire(\"Missing CLUSTERING ORDER for column %s\", c);\n            }\n            ++n;\n        }\n\n        // For COMPACT STORAGE, we reject any \"feature\" that we wouldn't be able to translate back to thrift.\n        if (useCompactStorage)\n        {\n            validateCompactTable(clusteringColumnProperties, columns);\n        }\n        else\n        {\n            // Static columns only make sense if we have at least one clustering column. Otherwise everything is static anyway\n            if (clusteringColumns.isEmpty() && !staticColumns.isEmpty())\n                throw ire(\"Static columns are only useful (and thus allowed) if the table has at least one clustering column\");\n        }\n\n        /*\n         * Counter table validation\n         */\n\n        boolean hasCounters = rawColumns.values().stream().anyMatch(c -> c.rawType.isCounter());\n        if (hasCounters)\n        {\n            // We've handled anything that is not a PRIMARY KEY so columns only contains NON-PK columns. So\n            // if it's a counter table, make sure we don't have non-counter types\n            if (columns.values().stream().anyMatch(t -> !t.type.isCounter()))\n                throw ire(\"Cannot mix counter and non counter columns in the same table\");\n\n            if (params.defaultTimeToLive > 0)\n                throw ire(\"Cannot set %s on a table with counters\", TableParams.Option.DEFAULT_TIME_TO_LIVE);\n        }\n","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java#L350-L386","documentation":"Static columns store a single value per partition, which is only meaningful when the table has clustering columns to vary within a partition. If the table has no clustering columns, all rows are one-per-partition anyway, so static columns add nothing — Cassandra rejects their declaration at CREATE TABLE time.","triggerScenarios":"CREATE TABLE t (pk int, v text STATIC, PRIMARY KEY (pk)) — a static column with a partition-key-only primary key.","commonSituations":"Copying a table definition with STATIC columns and simplifying the primary key to only the partition key; misunderstanding static column semantics in tables without clustering columns.","solutions":["Drop the STATIC keyword from the column definition.","Add at least one clustering column to the PRIMARY KEY so static columns become meaningful."],"exampleFix":"// before\nCREATE TABLE t (pk int, v text STATIC, PRIMARY KEY (pk));\n// after\nCREATE TABLE t (pk int, v text, PRIMARY KEY (pk));","handlingStrategy":"validation","validationCode":"// A table may declare STATIC columns only if it has clustering columns:\nboolean hasClustering = false; // true if PRIMARY KEY has columns after the partition key\nboolean hasStatic = false;      // any column declared STATIC\nif (hasStatic && !hasClustering) throw new IllegalArgumentException(\"STATIC column requires a clustering column\");","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (com.datastax.driver.core.exceptions.InvalidQueryException e) { if (e.getMessage().contains(\"Static columns are only useful\")) { /* drop STATIC or add clustering */ } else throw e; }","preventionTips":["Only mark columns STATIC in tables with composite (partition + clustering) primary keys.","Remember STATIC is meaningless in single-row-per-partition tables.","Validate generated DDL with a static-column check."],"tags":["cql","schema","create-table","static-columns"],"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"}