prestodb/presto · error · PrestoException

ALREADY_EXISTS

ALREADY_EXISTS

Error message

View already exists

What it means

Thrown by createView when a view with the same fully-qualified name already exists in the connector's metadata. Before writing view metadata, the connector checks the target schema's view names; a match aborts creation with the ALREADY_EXISTS error code. It is a name-collision guard for view creation.

Source

Thrown at presto-accumulo/src/main/java/com/facebook/presto/accumulo/AccumuloClient.java:543

        }

        if (!tableManager.exists(oldTable.getMetricsTableName())) {
            throw new PrestoException(ACCUMULO_TABLE_DNE, format("Table %s does not exist", oldTable.getMetricsTableName()));
        }

        if (tableManager.exists(newTable.getMetricsTableName())) {
            throw new PrestoException(ACCUMULO_TABLE_EXISTS, format("Table %s already exists", newTable.getMetricsTableName()));
        }

        tableManager.renameAccumuloTable(oldTable.getIndexTableName(), newTable.getIndexTableName());
        tableManager.renameAccumuloTable(oldTable.getMetricsTableName(), newTable.getMetricsTableName());
    }

    public void createView(SchemaTableName viewName, String viewData)
    {
        if (getSchemaNames().contains(viewName.getSchemaName())) {
            if (getViewNames(viewName.getSchemaName()).contains(viewName.getTableName())) {
                throw new PrestoException(ALREADY_EXISTS, "View already exists");
            }

            if (getTableNames(viewName.getSchemaName()).contains(viewName.getTableName())) {
                throw new PrestoException(INVALID_VIEW, "View already exists as data table");
            }
        }

        metaManager.createViewMetadata(new AccumuloView(viewName.getSchemaName(), viewName.getTableName(), viewData));
    }

    public void createOrReplaceView(SchemaTableName viewName, String viewData)
    {
        if (getView(viewName) != null) {
            metaManager.deleteViewMetadata(viewName);
        }

        metaManager.createViewMetadata(new AccumuloView(viewName.getSchemaName(), viewName.getTableName(), viewData));
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Drop the existing view first (DROP VIEW <schema>.<view>) then recreate it
  2. Use CREATE OR REPLACE VIEW if the engine/config supports it
  3. Check existing views via SHOW VIEWS / information_schema before creating
  4. Make deployment scripts idempotent so re-runs skip existing views

Example fix

// before
CREATE VIEW my_schema.my_view AS SELECT ...; -- view already exists
// after
DROP VIEW IF EXISTS my_schema.my_view;
CREATE VIEW my_schema.my_view AS SELECT ...;
Defensive patterns

Strategy: validation

Validate before calling

-- Pre-check in SQL before creating the view
SELECT count(*) FROM system.jdbc.views WHERE table_schema = 'my_schema' AND table_name = 'my_view'; -- expect 0

Type guard

boolean viewNameFree(SchemaTableName name) {
    return !getSchemaNames().contains(name.getSchemaName())
        || !getViewNames(name.getSchemaName()).contains(name.getTableName());
}

Try / catch

try {
    client.createView(viewName, viewData);
} catch (PrestoException e) {
    if (e.getErrorCode().getName().equals("ALREADY_EXISTS")) {
        // drop existing view or skip creation (idempotent deploy)
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling createView(viewName, viewData) where getViewNames(viewName.getSchemaName()).contains(viewName.getTableName()) is true — i.e., the schema exists and already contains a view with the same table name.

Common situations: Running CREATE VIEW without OR REPLACE / IF NOT EXISTS semantics twice; deploying scripts that recreate views idempotently; re-running a failed migration that partially created views; concurrent sessions creating the same view name.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/449e7449132f813b. Report an issue: GitHub.