{"record":{"id":"93f663eda60c865c","repo":"prestodb/presto","slug":"schema-already-exists-93f663","errorCode":"SCHEMA_ALREADY_EXISTS","errorMessage":"Target schema '%s' already exists","messagePattern":"Target schema '(.+?)' already exists","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/RenameSchemaTask.java","lineNumber":62,"sourceCode":"    }\n\n    @Override\n    public ListenableFuture<?> execute(RenameSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector, String query)\n    {\n        CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()), metadata);\n        CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget().getValue());\n        MetadataResolver metadataResolver = metadata.getMetadataResolver(session);\n\n        if (!metadataResolver.catalogExists(source.getCatalogName())) {\n            throw new SemanticException(MISSING_CATALOG, \"Catalog '%s' does not exist\", source.getCatalogName());\n        }\n\n        if (!metadataResolver.schemaExists(source)) {\n            throw new SemanticException(MISSING_SCHEMA, statement, \"Schema '%s' does not exist\", source);\n        }\n\n        if (metadataResolver.schemaExists(target)) {\n            throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, \"Target schema '%s' already exists\", target);\n        }\n\n        accessControl.checkCanRenameSchema(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), source, statement.getTarget().getValue());\n\n        metadata.renameSchema(session, source, statement.getTarget().getValue());\n\n        return immediateFuture(null);\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":72,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/RenameSchemaTask.java#L44-L72","documentation":"SemanticException thrown by RenameSchemaTask when the target schema name already exists in the catalog. Renaming into an existing schema would merge/collide namespaces, so Presto rejects it upfront with SCHEMA_ALREADY_EXISTS.","triggerScenarios":"ALTER SCHEMA catalog.source RENAME TO target where schemaExists(target) is true — the destination schema name is already taken.","commonSituations":"Re-running a rename migration after a partial success (source renamed, but a same-named target also exists); choosing a target name that collides with an existing schema; two environments merged onto one cluster.","solutions":["Pick a target schema name that doesn't exist (verify with SHOW SCHEMAS FROM catalog)","Drop or rename the pre-existing target schema if it's stale","Make the migration idempotent: if target exists and source doesn't, treat the rename as already done","Qualify and double-check the catalog — the collision may exist in a different catalog than intended"],"exampleFix":"-- before\nALTER SCHEMA sales.web RENAME TO archive; -- sales.archive already exists\n-- after\nALTER SCHEMA sales.web RENAME TO archive_2026; -- unique target","handlingStrategy":"validation","validationCode":"Set<String> schemas = showSchemas(\"sales\");\nif (schemas.contains(\"archive\")) { /* choose another target or drop stale schema */ }","typeGuard":null,"tryCatchPattern":"try {\n    execute(\"ALTER SCHEMA sales.web RENAME TO archive\");\n} catch (SemanticException e) {\n    if (e.getCode() == SCHEMA_ALREADY_EXISTS) { /* pick a unique target name or clean up */ }\n    else throw e;\n}","preventionTips":["Check target uniqueness with SHOW SCHEMAS before renaming","Use unique, dated target names in migrations","Clean up stale schemas from failed prior runs","Treat target-exists + source-missing as 'migration already applied' in replay logic"],"tags":["presto","ddl","schema-exists","name-conflict"],"backgroundTag":"resource-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"}