{"record":{"id":"bcd3d0eecef687e8","repo":"prestodb/presto","slug":"already-exists-bcd3d0","errorCode":"ALREADY_EXISTS","errorMessage":"Materialized view already exists: ","messagePattern":"Materialized view already exists: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java","lineNumber":822,"sourceCode":"        tableProperties.putAll(createIcebergViewProperties(session, nodeVersion.toString()));\n\n        ConnectorTableMetadata viewMetadata = new ConnectorTableMetadata(viewName, columns);\n\n        Table table = createTableObjectForViewCreation(\n                session,\n                viewMetadata,\n                tableProperties.build(),\n                new HiveTypeTranslator(),\n                metastoreContext,\n                encodeViewData(viewSql));\n\n        PrincipalPrivileges privileges = buildInitialPrivilegeSet(session.getUser());\n\n        try {\n            metastore.createTable(metastoreContext, table, privileges, emptyList());\n        }\n        catch (TableAlreadyExistsException e) {\n            throw new PrestoException(ALREADY_EXISTS, \"Materialized view already exists: \" + viewName);\n        }\n    }\n\n    @Override\n    protected void dropIcebergView(ConnectorSession session, SchemaTableName schemaTableName)\n    {\n        MetastoreContext metastoreContext = getMetastoreContext(session);\n\n        try {\n            metastore.dropTable(\n                    metastoreContext,\n                    schemaTableName.getSchemaName(),\n                    schemaTableName.getTableName(),\n                    true);\n        }\n        catch (TableNotFoundException e) {\n            throw new PrestoException(NOT_FOUND, \"Materialized view not found: \" + schemaTableName);\n        }","sourceCodeStart":804,"sourceCodeEnd":840,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java#L804-L840","documentation":"When creating (materializing) an Iceberg materialized view, the backing metastore table is created. If a table with the same name already exists (TableAlreadyExistsException from the metastore), Presto translates it into PrestoException ALREADY_EXISTS with 'Materialized view already exists: <name>'.","triggerScenarios":"Creating a materialized view whose name collides with an existing table or materialized view in the same schema; two concurrent CREATE MATERIALIZED VIEW statements racing on the same name.","commonSituations":"Name collision between a plain table and a materialized view; re-running a deployment script that creates MVs idempotently-naively; concurrent orchestration jobs creating the same MV.","solutions":["Choose a different materialized view name or drop/rename the existing object first","Check existence with SHOW TABLES / system.metadata before creating, and skip if present","Use CREATE OR REPLACE semantics if available, or DROP MATERIALIZED VIEW before recreate","Serialize creation logic in orchestration so concurrent jobs don't race on the same name"],"exampleFix":"// before\nCREATE MATERIALIZED VIEW sales.daily_mv AS SELECT ...; -- ALREADY_EXISTS\n// after\nDROP MATERIALIZED VIEW IF EXISTS sales.daily_mv;\nCREATE MATERIALIZED VIEW sales.daily_mv AS SELECT ...;","handlingStrategy":"try-catch","validationCode":"-- Check for an existing object with the target name first:\nSHOW TABLES FROM sales LIKE 'daily_mv';","typeGuard":null,"tryCatchPattern":"try {\n    stmt.execute(\"CREATE MATERIALIZED VIEW sales.daily_mv AS SELECT ...\");\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"already exists\")) {\n        // skip (idempotent), or DROP ... IF EXISTS then recreate\n    } else { throw e; }\n}","preventionTips":["Guard deployment scripts with DROP ... IF EXISTS or existence checks","Avoid reusing plain-table names for materialized views","Serialize MV creation in orchestration to prevent races","Adopt deterministic naming conventions per environment"],"tags":["iceberg","materialized-view","name-collision"],"backgroundTag":"object-already-exists","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}