{"record":{"id":"a3dd3951729fa8c2","repo":"apache/iceberg","slug":"table-with-same-name-already-exists-s-a3dd39","errorCode":null,"errorMessage":"Table with same name already exists: %s","messagePattern":"Table with same name already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":409,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java","lineNumber":1777,"sourceCode":"              response.metadata(),\n              endpoints);\n\n      return new BaseView(ops, ViewUtil.fullViewName(name(), identifier));\n    }\n\n    @Override\n    public View createOrReplace() {\n      try {\n        return replace(loadView());\n      } catch (NoSuchViewException e) {\n        return create();\n      }\n    }\n\n    @Override\n    public View replace() {\n      if (tableExists(context, identifier)) {\n        throw new AlreadyExistsException(\"Table with same name already exists: %s\", identifier);\n      }\n\n      return replace(loadView());\n    }\n\n    private LoadViewResponse loadView() {\n      Endpoint.check(\n          endpoints,\n          Endpoint.V1_LOAD_VIEW,\n          () ->\n              new NoSuchViewException(\n                  \"Unable to load view %s.%s: Server does not support endpoint %s\",\n                  name(), identifier, Endpoint.V1_LOAD_VIEW));\n\n      AuthSession contextualSession = authManager.contextualSession(context, catalogAuth);\n      return client\n          .withAuthSession(contextualSession)\n          .get(","sourceCodeStart":1759,"sourceCodeEnd":1795,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L1759-L1795","documentation":"An AlreadyExistsException thrown by the view Builder's replace() in RESTSessionCatalog when the target identifier currently resolves to a TABLE, not a view. Replacing a view cannot overwrite a table of the same name, so the operation is rejected before loading the view.","triggerScenarios":"Calling viewBuilder(identifier).replace() when tableExists(context, identifier) is true — i.e., a table already occupies that name in the catalog.","commonSituations":"Name collision between tables and views in the same namespace; a migration script recreating a view where a table was created; namespace confusion after default-namespace resolution.","solutions":["Check catalog.tableExists(identifier) before replace and pick a different name or drop the table first.","Catch org.apache.iceberg.exceptions.AlreadyExistsException and surface the naming conflict to the user.","Verify the intended object type with loadTable vs loadView to confirm what exists at that name.","Use distinct naming conventions for tables vs views to avoid collisions."],"exampleFix":"// before\ncatalog.buildView(ident).replace().createView(); // fails if a table named ident exists\n// after\nif (catalog.tableExists(ident)) { throw new IllegalStateException(\"name taken by table: \" + ident); }\ncatalog.buildView(ident).replace().createView();","handlingStrategy":"validation","validationCode":"if (catalog.tableExists(identifier)) { throw new IllegalStateException(\"cannot replace view: name held by table \" + identifier); }","typeGuard":null,"tryCatchPattern":"try { viewBuilder.replace().createView(); } catch (AlreadyExistsException e) { /* name occupied by a table */ }","preventionTips":["Check tableExists before building a replacing view","Use separate naming conventions for tables and views","Catch AlreadyExistsException on view replace flows","Audit namespaces for mixed table/view name collisions during migrations"],"tags":["rest","view","table","already-exists","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"}