prestodb/presto · error · PrestoException
ALREADY_EXISTS
ALREADY_EXISTS
Error message
Schema [%s] already exists
What it means
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.
Source
Thrown at presto-memory/src/main/java/com/facebook/presto/plugin/memory/MemoryMetadata.java:113
@Inject
public MemoryMetadata(NodeManager nodeManager, MemoryConnectorId connectorId)
{
this.nodeManager = requireNonNull(nodeManager, "nodeManager is null");
this.connectorId = requireNonNull(connectorId, "connectorId is null").toString();
this.schemas.add(SCHEMA_NAME);
}
@Override
public synchronized List<String> listSchemaNames(ConnectorSession session)
{
return ImmutableList.copyOf(schemas);
}
@Override
public synchronized void createSchema(ConnectorSession session, String schemaName, Map<String, Object> properties)
{
if (schemas.contains(schemaName)) {
throw new PrestoException(ALREADY_EXISTS, format("Schema [%s] already exists", schemaName));
}
schemas.add(schemaName);
}
@Override
public synchronized void dropSchema(ConnectorSession session, String schemaName)
{
if (!schemas.contains(schemaName)) {
throw new PrestoException(NOT_FOUND, format("Schema [%s] does not exist", schemaName));
}
boolean tablesExist = tables.values().stream()
.anyMatch(table -> table.getSchemaName().equals(schemaName));
if (tablesExist) {
throw new PrestoException(SCHEMA_NOT_EMPTY, "Schema not empty: " + schemaName);
}
View on GitHub (pinned to 55bb57d202)
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
Example fix
// before CREATE SCHEMA memory.test_schema; // after CREATE SCHEMA IF NOT EXISTS memory.test_schema;
Defensive patterns
Strategy: try-catch
Validate before calling
// Skip creation when schema already exists
if (metadata.listSchemaNames(session, "memory").contains(schemaName)) {
return; // already exists, nothing to do
}
metadata.createSchema(session, schemaName, ImmutableMap.of()); Try / catch
try {
metadata.createSchema(session, schemaName, properties);
} catch (PrestoException e) {
if (ALREADY_EXISTS.equals(e.getErrorCode())) {
log.info("Schema {} already exists, ignoring", schemaName);
} else throw e;
} Prevention
- Use CREATE SCHEMA IF NOT EXISTS
- Make DDL setup scripts idempotent
- Use unique schema names per test run
- Check SHOW SCHEMAS before creating
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/cb06b5858d04e37f.
Report an issue: GitHub.