apache/cassandra · error · InvalidRequestException

Cannot create materialized view

Error message

Cannot create materialized view '%s' - a table with the same name already exists

What it means

Name-collision guard in CreateViewStatement.apply(): a table (not a view) already exists in the keyspace with the same name as the materialized view being created. Tables and views share one namespace per keyspace, so the create is rejected with InvalidRequestException to avoid overwriting or shadowing the existing table.

Solutions

  1. Choose a different name for the materialized view; drop or rename the existing table if it is no longer needed (after verifying with DESCRIBE); check that the intended statement was not CREATE TABLE mistaken for CREATE MATERIALIZED VIEW.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java:158 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

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

    public Keyspaces apply(ClusterMetadata metadata)
    {
        /*
         * Basic dependency validations
         */
        Keyspaces schema = metadata.schema.getKeyspaces();
        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
        if (null == keyspace)
            throw ire("Keyspace '%s' doesn't exist", keyspaceName);

        if (keyspace.replicationStrategy.hasTransientReplicas())
            throw new InvalidRequestException("Materialized views are not supported on transiently replicated keyspaces");

        TableMetadata table = keyspace.tables.getNullable(tableName);
        if (null == table)
            throw ire("Base table '%s' doesn't exist", tableName);

        if (keyspace.hasTable(viewName))
            throw ire("Cannot create materialized view '%s' - a table with the same name already exists", viewName);

        if (keyspace.hasView(viewName))
        {
            if (ifNotExists)
                return schema;

            throw new AlreadyExistsException(keyspaceName, viewName);
        }

        /*
         * Base table validation
         */

        if (table.isCounter())
            throw ire("Materialized views are not supported on counter tables");

        if (table.isView())
            throw ire("Materialized views cannot be created against other materialized views");

View on GitHub (pinned to 88fd0f6a0e)