{"record":{"id":"a0a5462cca2a18f2","repo":"prestodb/presto","slug":"hive-metastore-error-a0a546","errorCode":"HIVE_METASTORE_ERROR","errorMessage":"Table already exists: %s.%s","messagePattern":"Table already exists: (.+?)\\.(.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-iceberg/src/main/java/com/facebook/presto/iceberg/HiveTableOperations.java","lineNumber":321,"sourceCode":"            PrincipalPrivileges privileges = new PrincipalPrivileges(\n                    ImmutableMultimap.<String, HivePrivilegeInfo>builder()\n                            .put(table.getOwner(), new HivePrivilegeInfo(SELECT, true, owner, owner))\n                            .put(table.getOwner(), new HivePrivilegeInfo(INSERT, true, owner, owner))\n                            .put(table.getOwner(), new HivePrivilegeInfo(UPDATE, true, owner, owner))\n                            .put(table.getOwner(), new HivePrivilegeInfo(DELETE, true, owner, owner))\n                            .build(),\n                    ImmutableMultimap.of());\n            try {\n                if (base == null) {\n                    metastore.createTable(metastoreContext, table, privileges, emptyList());\n                }\n                else {\n                    PartitionStatistics tableStats = metastore.getTableStatistics(metastoreContext, database, tableName);\n                    metastore.persistTable(metastoreContext, database, tableName, table, privileges, () -> tableStats, useHMSLock ? ImmutableMap.of() : hmsEnvContext(base.metadataFileLocation()));\n                }\n            }\n            catch (AlreadyExistsException e) {\n                throw new PrestoException(HIVE_METASTORE_ERROR, format(\"Table already exists: %s.%s\", database, tableName), e);\n            }\n            catch (CommitFailedException | CommitStateUnknownException e) {\n                throw e;\n            }\n            catch (Throwable e) {\n                if (e instanceof PrestoException && e.getCause() instanceof InvalidObjectException) {\n                    throw new ValidationException(e, \"Invalid Hive object for %s.%s\", database, tableName);\n                }\n                if (e.getMessage() != null\n                        && e.getMessage().contains(\"Table/View 'HIVE_LOCKS' does not exist\")) {\n                    throw new PrestoException(ICEBERG_COMMIT_ERROR,\n                            \"Failed to acquire locks from metastore because the underlying metastore \"\n                                    + \"table 'HIVE_LOCKS' does not exist. This can occur when using an embedded metastore which does not \"\n                                    + \"support transactions. To fix this use an alternative metastore.\",\n                            e);\n                }\n                CommitStatus commitStatus;\n                if (e.getMessage() != null","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-iceberg/src/main/java/com/facebook/presto/iceberg/HiveTableOperations.java#L303-L339","documentation":"During commit() of a new Iceberg table, metastore.persistTable() raised AlreadyExistsException, meaning a table with the same database.name already exists in the Hive Metastore. Presto rethrows it as a PrestoException with code HIVE_METASTORE_ERROR.","triggerScenarios":"Calling CREATE TABLE / CREATE TABLE AS against an Iceberg catalog when the target table already exists in HMS (e.g. created concurrently or left over from a previous run).","commonSituations":"Idempotency-less CI/CD or migration scripts run twice; race between two sessions creating the same table; inconsistent catalogs where the Iceberg metadata files are absent but the HMS entry exists.","solutions":["Use CREATE TABLE IF NOT EXISTS (or check existence via SHOW TABLES / system metadata first).","Drop or rename the existing table if it is stale/unwanted.","Serialize table-creation logic in deployment scripts to avoid concurrent creates."],"exampleFix":"-- before\nCREATE TABLE iceberg.db.events (...) ;\n-- after\nCREATE TABLE IF NOT EXISTS iceberg.db.events (...);","handlingStrategy":"validation","validationCode":"boolean exists = metadata.getSession().getMetadata().getTableHandle(session, tableName) != null;\nif (exists) throw new IllegalStateException(\"Table exists: \" + tableName);","typeGuard":null,"tryCatchPattern":"try { createTable(...); }\ncatch (PrestoException e) { if (e.getErrorCode() == HIVE_METASTORE_ERROR.toErrorCode()) { /* handle existing table */ } }","preventionTips":["Use CREATE TABLE IF NOT EXISTS in idempotent scripts.","Check SHOW TABLES / information_schema before create.","Guard concurrent deployments from creating the same table."],"tags":["iceberg","hive-metastore","table-already-exists","ddl"],"backgroundTag":"table-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"}