apache/cassandra · error · InvalidRequestException

Bind variables are not allowed in CREATE MATERIALIZED VIEW…

Error message

Bind variables are not allowed in CREATE MATERIALIZED VIEW statements

What it means

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.

Solutions

  1. Inline literal column names and values instead of using ? markers
  2. Generate the DDL string in application code with values substituted, then execute it unprepared

Example fix

// before
session.prepare("CREATE MATERIALIZED VIEW t.mv AS SELECT * FROM t WHERE k = ? PRIMARY KEY (k)");
// after
session.execute("CREATE MATERIALIZED VIEW t.mv AS SELECT * FROM t WHERE k IS NOT NULL PRIMARY KEY (k)");
Defensive patterns

Strategy: validation

Validate before calling

/\?|:[a-zA-Z_]\w*/.test(ddl) && ddl.trim().toUpperCase().startsWith('CREATE MATERIALIZED VIEW') && (throw new Error('Bind variables not allowed in MV DDL'));

Try / catch

try { session.execute(ddl); } catch (e) { if (e instanceof InvalidQueryError && /Bind variables/.test(e.message)) { /* regenerate DDL with inlined literals */ } else throw e; }

Prevention

When it happens

Trigger: Executing CREATE MATERIALIZED VIEW ... with ? placeholders in the SELECT list, WHERE clause, or PRIMARY KEY definition, e.g. via a prepared-statement style call.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/daa13cc517977e06. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java:458

        public Raw(QualifiedName tableName, QualifiedName viewName, List<RawSelector> rawColumns, WhereClause whereClause, boolean ifNotExists)
        {
            this.tableName = tableName;
            this.viewName = viewName;
            this.rawColumns = rawColumns;
            this.whereClause = whereClause;
            this.ifNotExists = ifNotExists;
        }

        public CreateViewStatement prepare(ClientState state)
        {
            String keyspaceName = viewName.hasKeyspace() ? viewName.getKeyspace() : state.getKeyspace();

            if (tableName.hasKeyspace() && !keyspaceName.equals(tableName.getKeyspace()))
                throw ire("Cannot create a materialized view on a table in a different keyspace");

            if (!bindVariables.isEmpty())
                throw ire("Bind variables are not allowed in CREATE MATERIALIZED VIEW statements");

            if (null == partitionKeyColumns)
                throw ire("No PRIMARY KEY specifed for view '%s' (exactly one required)", viewName);

            return new CreateViewStatement(keyspaceName,
                                           tableName.getName(),
                                           viewName.getName(),

                                           rawColumns,
                                           partitionKeyColumns,
                                           clusteringColumns,

                                           whereClause,

                                           clusteringOrder,
                                           attrs,

                                           ifNotExists);

View on GitHub (pinned to 88fd0f6a0e)