{"record":{"id":"f9f4682461cb5474","repo":"apache/iceberg","slug":"cannot-rename-s-to-s-table-already-exists-f9f468","errorCode":null,"errorMessage":"Cannot rename %s to %s. Table already exists","messagePattern":"Cannot rename (.+?) to (.+?)\\. Table already exists","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":724,"sourceCode":"  public void renameView(TableIdentifier from, TableIdentifier to) {\n    if (schemaVersion != JdbcUtil.SchemaVersion.V1) {\n      throw new UnsupportedOperationException(VIEW_WARNING_LOG_MESSAGE);\n    }\n\n    if (from.equals(to)) {\n      return;\n    }\n\n    if (!namespaceExists(to.namespace())) {\n      throw new NoSuchNamespaceException(\"Namespace does not exist: %s\", to.namespace());\n    }\n\n    if (!viewExists(from)) {\n      throw new NoSuchViewException(\"View does not exist\");\n    }\n\n    if (tableExists(to)) {\n      throw new AlreadyExistsException(\"Cannot rename %s to %s. Table already exists\", from, to);\n    }\n\n    if (viewExists(to)) {\n      throw new AlreadyExistsException(\"Cannot rename %s to %s. View already exists\", from, to);\n    }\n\n    int updatedRecords =\n        execute(\n            err -> {\n              if (JdbcUtil.isConstraintViolation(err)) {\n                throw new AlreadyExistsException(\n                    \"Cannot rename %s to %s. View already exists\", from, to);\n              }\n            },\n            JdbcUtil.RENAME_VIEW_SQL,\n            JdbcUtil.namespaceToString(to.namespace()),\n            to.name(),\n            catalogName,","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L706-L742","documentation":"JdbcCatalog.renameView throws AlreadyExistsException when the destination identifier collides with an existing TABLE. Views and tables share the identifier space in this catalog, so a view cannot be renamed onto an existing table name.","triggerScenarios":"Calling catalog.renameView(from, to) where tableExists(to) is true — the target name is already taken by a table in the same namespace.","commonSituations":"Reusing a name that was previously a table, migrating tables to views (or vice versa) without cleaning up, generating target names programmatically that collide.","solutions":["Choose a different destination name that does not collide with existing tables.","Check catalog.tableExists(to) before renaming and pick an alternate name if taken.","Drop the conflicting table first if it is truly obsolete (destructive — confirm first).","Catch AlreadyExistsException and surface a clear conflict to the user."],"exampleFix":"// before\ncatalog.renameView(from, to); // fails if a table named 'to' exists\n\n// after\nif (catalog.tableExists(to)) {\n  throw new IllegalStateException(\"Target name in use by a table: \" + to);\n}\ncatalog.renameView(from, to);","handlingStrategy":"validation","validationCode":"if (catalog.tableExists(to)) {\n  throw new IllegalArgumentException(\"Target name taken by table: \" + to);\n}\ncatalog.renameView(from, to);","typeGuard":null,"tryCatchPattern":"try {\n  catalog.renameView(from, to);\n} catch (AlreadyExistsException e) {\n  // pick another destination name or surface conflict\n}","preventionTips":["Check both tableExists and viewExists on the target before renaming","Use name-generation that appends suffixes on collision","Keep table and view naming conventions distinct"],"tags":["jdbc","rename","view","conflict"],"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-14T16:17:12.679Z"}