{"record":{"id":"cb06b5858d04e37f","repo":"prestodb/presto","slug":"already-exists-cb06b5","errorCode":"ALREADY_EXISTS","errorMessage":"Schema [%s] already exists","messagePattern":"Schema \\[(.+?)\\] already exists","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-memory/src/main/java/com/facebook/presto/plugin/memory/MemoryMetadata.java","lineNumber":113,"sourceCode":"    @Inject\n    public MemoryMetadata(NodeManager nodeManager, MemoryConnectorId connectorId)\n    {\n        this.nodeManager = requireNonNull(nodeManager, \"nodeManager is null\");\n        this.connectorId = requireNonNull(connectorId, \"connectorId is null\").toString();\n        this.schemas.add(SCHEMA_NAME);\n    }\n\n    @Override\n    public synchronized List<String> listSchemaNames(ConnectorSession session)\n    {\n        return ImmutableList.copyOf(schemas);\n    }\n\n    @Override\n    public synchronized void createSchema(ConnectorSession session, String schemaName, Map<String, Object> properties)\n    {\n        if (schemas.contains(schemaName)) {\n            throw new PrestoException(ALREADY_EXISTS, format(\"Schema [%s] already exists\", schemaName));\n        }\n        schemas.add(schemaName);\n    }\n\n    @Override\n    public synchronized void dropSchema(ConnectorSession session, String schemaName)\n    {\n        if (!schemas.contains(schemaName)) {\n            throw new PrestoException(NOT_FOUND, format(\"Schema [%s] does not exist\", schemaName));\n        }\n\n        boolean tablesExist = tables.values().stream()\n                .anyMatch(table -> table.getSchemaName().equals(schemaName));\n\n        if (tablesExist) {\n            throw new PrestoException(SCHEMA_NOT_EMPTY, \"Schema not empty: \" + schemaName);\n        }\n","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-memory/src/main/java/com/facebook/presto/plugin/memory/MemoryMetadata.java#L95-L131","documentation":"The Memory connector's MemoryMetadata.createSchema is guarded against re-creating an existing schema. Because all schemas are held in-memory and checked with schemas.contains(schemaName), creating a schema name that is already registered throws PrestoException ALREADY_EXISTS with the schema name in brackets. This is a standard idempotency guard for DDL.","triggerScenarios":"Running CREATE SCHEMA memory.<name> twice without IF NOT EXISTS; concurrent session re-running bootstrap DDL against a memory catalog that already created the schema.","commonSituations":"Idempotent deployment scripts that re-run CREATE SCHEMA on every deploy; test harnesses sharing a memory catalog across test runs; race between two setup steps in the same session.","solutions":["Use CREATE SCHEMA IF NOT EXISTS memory.<name>","Check existence first via SHOW SCHEMAS FROM memory before creating","Use a unique schema name per test/deploy run","Catch ALREADY_EXISTS and treat it as success in setup scripts"],"exampleFix":"// before\nCREATE SCHEMA memory.test_schema;\n// after\nCREATE SCHEMA IF NOT EXISTS memory.test_schema;","handlingStrategy":"try-catch","validationCode":"// Skip creation when schema already exists\nif (metadata.listSchemaNames(session, \"memory\").contains(schemaName)) {\n    return; // already exists, nothing to do\n}\nmetadata.createSchema(session, schemaName, ImmutableMap.of());","typeGuard":null,"tryCatchPattern":"try {\n    metadata.createSchema(session, schemaName, properties);\n} catch (PrestoException e) {\n    if (ALREADY_EXISTS.equals(e.getErrorCode())) {\n        log.info(\"Schema {} already exists, ignoring\", schemaName);\n    } else throw e;\n}","preventionTips":["Use CREATE SCHEMA IF NOT EXISTS","Make DDL setup scripts idempotent","Use unique schema names per test run","Check SHOW SCHEMAS before creating"],"tags":["ddl","schema","already-exists","memory-connector"],"backgroundTag":"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"}