{"record":{"id":"69bb841f0a4c35d4","repo":"prestodb/presto","slug":"missing-schema-69bb84","errorCode":"MISSING_SCHEMA","errorMessage":"Schema '%s' does not exist","messagePattern":"Schema '(.+?)' does not exist","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/RenameSchemaTask.java","lineNumber":58,"sourceCode":"    @Override\n    public String getName()\n    {\n        return \"RENAME SCHEMA\";\n    }\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":40,"sourceCodeEnd":72,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/RenameSchemaTask.java#L40-L72","documentation":"SemanticException thrown by RenameSchemaTask when the source schema does not exist in the (validated) catalog. metadataResolver.schemaExists(source) returning false aborts the rename, since there is nothing to rename. The catalog was already validated, so this is specifically a missing schema.","triggerScenarios":"ALTER SCHEMA catalog.source RENAME TO target where schemaExists(source) is false. Includes typos, wrong-case schema names, and schemas dropped concurrently.","commonSituations":"Schema already renamed by a prior run of the same script; typo in schema name; schema dropped by cleanup jobs; running migrations against the wrong catalog.","solutions":["Verify with SHOW SCHEMAS FROM catalog that the source schema exists","Make the migration idempotent: check information_schema or skip if the target schema already exists","Correct the schema name spelling/case in the statement","Confirm you're renaming in the intended catalog/environment"],"exampleFix":"-- before\nALTER SCHEMA sales.web RENAME TO web_archive; -- second run: web already renamed\n-- after\n-- guard in migration runner\nSELECT count(*) FROM information_schema.schemata WHERE schema_name='web'; -- skip rename if 0\nALTER SCHEMA sales.web RENAME TO web_archive;","handlingStrategy":"validation","validationCode":"ResultSet rs = stmt.executeQuery(\"SHOW SCHEMAS FROM sales\");\nSet<String> schemas = new HashSet<>();\nwhile (rs.next()) schemas.add(rs.getString(\"Schema\").toLowerCase());\nif (!schemas.contains(\"web\")) { /* already renamed or never existed */ }","typeGuard":null,"tryCatchPattern":"try {\n    execute(\"ALTER SCHEMA sales.web RENAME TO web_archive\");\n} catch (SemanticException e) {\n    if (e.getCode() == MISSING_SCHEMA && schemaExists(\"sales.web_archive\")) { /* already done — skip */ }\n    else throw e;\n}","preventionTips":["Verify source schema with SHOW SCHEMAS before renaming","Design idempotent migrations: detect target-exists + source-missing as 'already applied'","Check spelling/case of schema identifiers"],"tags":["presto","ddl","missing-schema","sql"],"backgroundTag":"schema-not-found","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"}