{"record":{"id":"449e7449132f813b","repo":"prestodb/presto","slug":"already-exists","errorCode":"ALREADY_EXISTS","errorMessage":"View already exists","messagePattern":"View already exists","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-accumulo/src/main/java/com/facebook/presto/accumulo/AccumuloClient.java","lineNumber":543,"sourceCode":"        }\n\n        if (!tableManager.exists(oldTable.getMetricsTableName())) {\n            throw new PrestoException(ACCUMULO_TABLE_DNE, format(\"Table %s does not exist\", oldTable.getMetricsTableName()));\n        }\n\n        if (tableManager.exists(newTable.getMetricsTableName())) {\n            throw new PrestoException(ACCUMULO_TABLE_EXISTS, format(\"Table %s already exists\", newTable.getMetricsTableName()));\n        }\n\n        tableManager.renameAccumuloTable(oldTable.getIndexTableName(), newTable.getIndexTableName());\n        tableManager.renameAccumuloTable(oldTable.getMetricsTableName(), newTable.getMetricsTableName());\n    }\n\n    public void createView(SchemaTableName viewName, String viewData)\n    {\n        if (getSchemaNames().contains(viewName.getSchemaName())) {\n            if (getViewNames(viewName.getSchemaName()).contains(viewName.getTableName())) {\n                throw new PrestoException(ALREADY_EXISTS, \"View already exists\");\n            }\n\n            if (getTableNames(viewName.getSchemaName()).contains(viewName.getTableName())) {\n                throw new PrestoException(INVALID_VIEW, \"View already exists as data table\");\n            }\n        }\n\n        metaManager.createViewMetadata(new AccumuloView(viewName.getSchemaName(), viewName.getTableName(), viewData));\n    }\n\n    public void createOrReplaceView(SchemaTableName viewName, String viewData)\n    {\n        if (getView(viewName) != null) {\n            metaManager.deleteViewMetadata(viewName);\n        }\n\n        metaManager.createViewMetadata(new AccumuloView(viewName.getSchemaName(), viewName.getTableName(), viewData));\n    }","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-accumulo/src/main/java/com/facebook/presto/accumulo/AccumuloClient.java#L525-L561","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Drop the existing view first (DROP VIEW <schema>.<view>) then recreate it","Use CREATE OR REPLACE VIEW if the engine/config supports it","Check existing views via SHOW VIEWS / information_schema before creating","Make deployment scripts idempotent so re-runs skip existing views"],"exampleFix":"// before\nCREATE VIEW my_schema.my_view AS SELECT ...; -- view already exists\n// after\nDROP VIEW IF EXISTS my_schema.my_view;\nCREATE VIEW my_schema.my_view AS SELECT ...;","handlingStrategy":"validation","validationCode":"-- Pre-check in SQL before creating the view\nSELECT count(*) FROM system.jdbc.views WHERE table_schema = 'my_schema' AND table_name = 'my_view'; -- expect 0","typeGuard":"boolean viewNameFree(SchemaTableName name) {\n    return !getSchemaNames().contains(name.getSchemaName())\n        || !getViewNames(name.getSchemaName()).contains(name.getTableName());\n}","tryCatchPattern":"try {\n    client.createView(viewName, viewData);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"ALREADY_EXISTS\")) {\n        // drop existing view or skip creation (idempotent deploy)\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check existing views with SHOW VIEWS before CREATE VIEW","Use CREATE OR REPLACE VIEW or DROP VIEW IF EXISTS for idempotent scripts","Adopt unique, versioned view names in migration tooling","Serialize concurrent DDL so two sessions cannot create the same view"],"tags":["accumulo","view-exists","name-collision","ddl"],"backgroundTag":"table-already-exists","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}