{"record":{"id":"1edf77f1c093b24b","repo":"apache/iceberg","slug":"view-with-same-name-already-exists-s-1edf77","errorCode":null,"errorMessage":"View with same name already exists: %s","messagePattern":"View with same name already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":921,"sourceCode":"  }\n\n  /**\n   * The purpose of this class is to add view detection only when SchemaVersion.V1 schema is used\n   * when replacing a table.\n   */\n  protected class ViewAwareTableBuilder extends BaseMetastoreCatalogTableBuilder {\n\n    private final TableIdentifier identifier;\n\n    public ViewAwareTableBuilder(TableIdentifier identifier, Schema schema) {\n      super(identifier, schema);\n      this.identifier = identifier;\n    }\n\n    @Override\n    public Transaction replaceTransaction() {\n      if (schemaVersion == JdbcUtil.SchemaVersion.V1 && viewExists(identifier)) {\n        throw new AlreadyExistsException(\"View with same name already exists: %s\", identifier);\n      }\n\n      return super.replaceTransaction();\n    }\n  }\n}\n","sourceCodeStart":903,"sourceCodeEnd":928,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L903-L928","documentation":"In JdbcCatalog's view builder transaction wrapper, replaceTransaction() under SchemaVersion.V1 first checks viewExists(identifier); if a view with the same name exists it throws AlreadyExistsException \"View with same name already exists: %s\". In V1 schema, tables and views share a namespace, so replacing a table via transaction is blocked when a view occupies the name.","triggerScenarios":"Calling transaction.replaceTransaction() on a JdbcCatalog view builder (e.g., via replaceTransaction on a View or table builder transaction) where an entity with the same identifier already exists as a view and schemaVersion is V1.","commonSituations":"Creating/replacing a table with the same name as an existing view; name reuse after a table was dropped but a view was created with the same name; upgrading from setups that allowed shared names.","solutions":["Drop the conflicting view first with catalog.dropView(identifier), then perform the replace","Choose a different name for the new table/view","Upgrade the JDBC catalog schema version (V1 -> V0/V1 handling differs; use a schema where views are stored separately) if name sharing is required","Check viewExists(identifier) before starting a replace transaction"],"exampleFix":"// before\nTransaction t = catalog.buildTable(ident, schema).replaceTransaction();\n// after\nif (catalog.viewExists(ident)) {\n  catalog.dropView(ident);\n}\nTransaction t = catalog.buildTable(ident, schema).replaceTransaction();","handlingStrategy":"validation","validationCode":"if (catalog.viewExists(ident)) {\n  throw new IllegalStateException(\"Name occupied by a view: \" + ident);\n}\nTransaction t = catalog.buildTable(ident, schema).replaceTransaction();","typeGuard":null,"tryCatchPattern":"try {\n  Transaction t = catalog.buildTable(ident, schema).replaceTransaction();\n} catch (AlreadyExistsException e) {\n  // a view occupies this name: drop it or pick a new name\n  throw e;\n}","preventionTips":["Check viewExists before replaceTransaction when names may be shared","Keep table and view naming namespaces distinct by convention","Drop stale views created from old table names before reusing names","Understand your catalog schemaVersion's name-sharing semantics"],"tags":["jdbc","catalog","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"}