{"record":{"id":"daa13cc517977e06","repo":"apache/cassandra","slug":"bind-variables-are-not-allowed-in-create-materiali","errorCode":null,"errorMessage":"Bind variables are not allowed in CREATE MATERIALIZED VIEW statements","messagePattern":"Bind variables are not allowed in CREATE MATERIALIZED VIEW statements","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java","lineNumber":458,"sourceCode":"\n        public Raw(QualifiedName tableName, QualifiedName viewName, List<RawSelector> rawColumns, WhereClause whereClause, boolean ifNotExists)\n        {\n            this.tableName = tableName;\n            this.viewName = viewName;\n            this.rawColumns = rawColumns;\n            this.whereClause = whereClause;\n            this.ifNotExists = ifNotExists;\n        }\n\n        public CreateViewStatement prepare(ClientState state)\n        {\n            String keyspaceName = viewName.hasKeyspace() ? viewName.getKeyspace() : state.getKeyspace();\n\n            if (tableName.hasKeyspace() && !keyspaceName.equals(tableName.getKeyspace()))\n                throw ire(\"Cannot create a materialized view on a table in a different keyspace\");\n\n            if (!bindVariables.isEmpty())\n                throw ire(\"Bind variables are not allowed in CREATE MATERIALIZED VIEW statements\");\n\n            if (null == partitionKeyColumns)\n                throw ire(\"No PRIMARY KEY specifed for view '%s' (exactly one required)\", viewName);\n\n            return new CreateViewStatement(keyspaceName,\n                                           tableName.getName(),\n                                           viewName.getName(),\n\n                                           rawColumns,\n                                           partitionKeyColumns,\n                                           clusteringColumns,\n\n                                           whereClause,\n\n                                           clusteringOrder,\n                                           attrs,\n\n                                           ifNotExists);","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java#L440-L476","documentation":"CREATE MATERIALIZED VIEW does not support bind markers ('?') anywhere in the statement: view DDL must be fully specified at execution time because it is not a parameterized query. prepare() rejects any statement carrying bind variables.","triggerScenarios":"Executing CREATE MATERIALIZED VIEW ... with ? placeholders in the SELECT list, WHERE clause, or PRIMARY KEY definition, e.g. via a prepared-statement style call.","commonSituations":"Attempting to prepare a CREATE MV statement like a DML statement; template-driven schema tools substituting values with bind markers; porting prepared-statement code paths to DDL.","solutions":["Inline literal column names and values instead of using ? markers","Generate the DDL string in application code with values substituted, then execute it unprepared"],"exampleFix":"// before\nsession.prepare(\"CREATE MATERIALIZED VIEW t.mv AS SELECT * FROM t WHERE k = ? PRIMARY KEY (k)\");\n// after\nsession.execute(\"CREATE MATERIALIZED VIEW t.mv AS SELECT * FROM t WHERE k IS NOT NULL PRIMARY KEY (k)\");","handlingStrategy":"validation","validationCode":"/\\?|:[a-zA-Z_]\\w*/.test(ddl) && ddl.trim().toUpperCase().startsWith('CREATE MATERIALIZED VIEW') && (throw new Error('Bind variables not allowed in MV DDL'));","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (e instanceof InvalidQueryError && /Bind variables/.test(e.message)) { /* regenerate DDL with inlined literals */ } else throw e; }","preventionTips":["Never pass DDL through prepare()/bind pipelines","Use string templating, not bind markers, to parameterize DDL generation"],"tags":["cql","materialized-view","bind-variables","ddl"],"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"}