{"record":{"id":"f517894dc4ece88f","repo":"apache/cassandra","slug":"cannot-include-static-column-s-in-materialized","errorCode":null,"errorMessage":"Cannot include static column '%s' in materialized view '%s'","messagePattern":"Cannot include static column '(.+?)' in materialized view '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java","lineNumber":231,"sourceCode":"        {\n            if (null != selector.alias)\n                throw ire(\"Cannot use aliases when defining a materialized view (got %s)\", selector);\n\n            if (!(selector.selectable instanceof Selectable.RawIdentifier))\n                throw ire(\"Can only select columns by name when defining a materialized view (got %s)\", selector.selectable);\n\n            // will throw IRE if the column doesn't exist in the base table\n            Selectable.RawIdentifier rawIdentifier = (Selectable.RawIdentifier) selector.selectable;\n            ColumnMetadata column = rawIdentifier.columnMetadata(table);\n\n            selectedColumns.add(column.name);\n        });\n\n        selectedColumns.stream()\n                       .map(table::getColumn)\n                       .filter(ColumnMetadata::isStatic)\n                       .findAny()\n                       .ifPresent(c -> { throw ire(\"Cannot include static column '%s' in materialized view '%s'\", c, viewName); });\n\n        /*\n         * Process PRIMARY KEY columns and CLUSTERING ORDER BY clause\n         */\n\n        if (partitionKeyColumns.isEmpty())\n            throw ire(\"Must provide at least one partition key column for materialized view '%s'\", viewName);\n\n        HashSet<ColumnIdentifier> primaryKeyColumns = new HashSet<>();\n\n        concat(partitionKeyColumns, clusteringColumns).forEach(name ->\n        {\n            ColumnMetadata column = table.getColumn(name);\n            if (null == column || !selectedColumns.contains(name))\n                throw ire(\"Unknown column '%s' referenced in PRIMARY KEY for materialized view '%s'\", name, viewName);\n\n            if (!primaryKeyColumns.add(name))\n                throw ire(\"Duplicate column '%s' in PRIMARY KEY clause for materialized view '%s'\", name, viewName);","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java#L213-L249","documentation":"Static columns belong to the partition, not to a row, so a materialized view keyed by clustering columns cannot consistently hold a static column value. MVs do not support static columns at all, and any static column in the SELECT list causes rejection.","triggerScenarios":"CREATE MATERIALIZED VIEW whose SELECT includes a static column of the base table (e.g. a partition-level attribute column declared STATIC).","commonSituations":"Tables modeled with partition-level metadata stored in static columns; users then filter by clustering columns via an MV and hit this restriction.","solutions":["Remove the static column from the view's SELECT list","Duplicate the static value into a regular column if it must appear in every view row","Keep static data in the base table and fetch it separately in the application"],"exampleFix":"// before\nCREATE MATERIALIZED VIEW mv AS SELECT static_meta, pk, ck FROM base WHERE ck IS NOT NULL;\n// after\nCREATE MATERIALIZED VIEW mv AS SELECT pk, ck, col1 FROM base WHERE ck IS NOT NULL;","handlingStrategy":"validation","validationCode":"for (String col : selectColumns) if (baseStaticColumns.contains(col)) throw new IllegalArgumentException(\"Static column in MV select: \" + col);","typeGuard":null,"tryCatchPattern":"try { session.execute(createMvStmt); } catch (InvalidQueryException e) { if (e.getMessage().contains(\"static column\")) { /* remove static column from SELECT */ } }","preventionTips":["Inspect system_schema.columns (kind='static') before designing an MV","Keep partition-level metadata out of MV projections"],"tags":["cql","materialized-view","static-column"],"backgroundTag":"unsupported-operation","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"}