{"record":{"id":"e4c5a9116335234a","repo":"apache/iceberg","slug":"table-already-exists-s-e4c5a9","errorCode":null,"errorMessage":"Table already exists: %s","messagePattern":"Table already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":373,"sourceCode":"  public void renameTable(TableIdentifier from, TableIdentifier to) {\n    if (from.equals(to)) {\n      return;\n    }\n\n    if (!tableExists(from)) {\n      throw new NoSuchTableException(\"Table does not exist: %s\", from);\n    }\n\n    if (!namespaceExists(to.namespace())) {\n      throw new NoSuchNamespaceException(\"Namespace does not exist: %s\", to.namespace());\n    }\n\n    if (schemaVersion == JdbcUtil.SchemaVersion.V1 && viewExists(to)) {\n      throw new AlreadyExistsException(\"Cannot rename %s to %s. View already exists\", from, to);\n    }\n\n    if (tableExists(to)) {\n      throw new AlreadyExistsException(\"Table already exists: %s\", to);\n    }\n\n    int updatedRecords =\n        execute(\n            err -> {\n              if (JdbcUtil.isConstraintViolation(err)) {\n                throw new AlreadyExistsException(\"Table already exists: %s\", to);\n              }\n            },\n            (schemaVersion == JdbcUtil.SchemaVersion.V1)\n                ? JdbcUtil.V1_RENAME_TABLE_SQL\n                : JdbcUtil.V0_RENAME_TABLE_SQL,\n            JdbcUtil.namespaceToString(to.namespace()),\n            to.name(),\n            catalogName,\n            JdbcUtil.namespaceToString(from.namespace()),\n            from.name());\n","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L355-L391","documentation":"JdbcCatalog.renameTable throws AlreadyExistsException when the target table identifier already exists as a table. The check runs before the UPDATE so an existing destination table is never overwritten. It is a pre-flight guard in addition to the database primary-key constraint check that follows.","triggerScenarios":"Calling catalog.renameTable(from, to) where catalog.tableExists(to) is true — i.e. a table with the same namespace and name as 'to' already exists.","commonSituations":"Retrying a rename after a previous partial rename; scripted pipelines that re-run against an already-renamed catalog; two clients renaming concurrently to the same target name.","solutions":["Use a different target name or drop the existing table at the target first","Check catalog.tableExists(to) before issuing the rename","Handle AlreadyExistsException in the caller and treat it as idempotent success if the rename already completed"],"exampleFix":"// before\ncatalog.renameTable(from, to); // may throw\n// after\nif (!catalog.tableExists(to)) {\n  catalog.renameTable(from, to);\n}","handlingStrategy":"try-catch","validationCode":"if (catalog.tableExists(to)) { throw new IllegalStateException(\"target table exists\"); }","typeGuard":"boolean targetFree = !catalog.tableExists(to);","tryCatchPattern":"try { catalog.renameTable(from, to); } catch (AlreadyExistsException e) { /* target occupied: choose another name or drop first */ }","preventionTips":["Always probe tableExists(to) before renameTable","Make rename pipelines idempotent: treat AlreadyExistsException after a retry as success","Use unique target names (suffixes/timestamps) in concurrent workflows"],"tags":["jdbc-catalog","already-exists","rename"],"backgroundTag":"file-already-exists","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}