{"record":{"id":"5f03b749e7fc24b0","repo":"apache/iceberg","slug":"table-with-same-name-already-exists-s-5f03b7","errorCode":null,"errorMessage":"Table with same name already exists: %s","messagePattern":"Table with same name already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcViewOperations.java","lineNumber":183,"sourceCode":"    if (updatedRecords == 1) {\n      LOG.debug(\"Successfully committed to existing view: {}\", viewIdentifier);\n    } else {\n      throw new CommitFailedException(\n          \"Failed to update view %s from catalog %s\", viewIdentifier, catalogName);\n    }\n  }\n\n  private void createView(String newMetadataLocation) throws SQLException, InterruptedException {\n    Namespace namespace = viewIdentifier.namespace();\n    if (PropertyUtil.propertyAsBoolean(catalogProperties, JdbcUtil.STRICT_MODE_PROPERTY, false)\n        && !JdbcUtil.namespaceExists(catalogName, connections, namespace)) {\n      throw new NoSuchNamespaceException(\n          \"Cannot create view %s in catalog %s. Namespace %s does not exist\",\n          viewIdentifier, catalogName, namespace);\n    }\n\n    if (JdbcUtil.tableExists(JdbcUtil.SchemaVersion.V1, catalogName, connections, viewIdentifier)) {\n      throw new AlreadyExistsException(\"Table with same name already exists: %s\", viewIdentifier);\n    }\n\n    if (JdbcUtil.viewExists(catalogName, connections, viewIdentifier)) {\n      throw new AlreadyExistsException(\"View already exists: %s\", viewIdentifier);\n    }\n\n    int insertRecord =\n        JdbcUtil.doCommitCreateView(\n            connections, catalogName, namespace, viewIdentifier, newMetadataLocation);\n\n    if (insertRecord == 1) {\n      LOG.debug(\"Successfully committed to new view: {}\", viewIdentifier);\n    } else {\n      throw new CommitFailedException(\n          \"Failed to create view %s in catalog %s\", viewIdentifier, catalogName);\n    }\n  }\n}","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcViewOperations.java#L165-L201","documentation":"Before inserting a new view row, createView checks whether a TABLE with the same name already exists in the JDBC catalog. If it does, AlreadyExistsException is thrown, because Iceberg namespaces one object per name and a table/view name collision is unresolvable.","triggerScenarios":"Committing a new view (base == null) whose identifier collides with an existing table row in iceberg_tables for the same catalog and namespace.","commonSituations":"A name previously used for a table is reused for a view without dropping the table; cross-tool confusion where another engine created a table under the same identifier; test code reusing identifiers without cleanup.","solutions":["Choose a different name for the view, or drop the existing table first (catalog.dropTable(identifier))","Check for the collision before creating: catalog.tableExists(identifier) / catalog.viewExists(identifier)","Catch AlreadyExistsException to surface a friendly 'name in use' message to end users","Clean up leftover tables from failed/aborted jobs in shared test environments"],"exampleFix":"// before\ncatalog.buildView(identify).createColumn(...).create();\n// after\nif (catalog.tableExists(identifier)) {\n  throw new IllegalArgumentException(\"Name in use by table: \" + identifier);\n}\ncatalog.buildView(identifier).createColumn(...).create();","handlingStrategy":"validation","validationCode":"if (catalog.tableExists(identifier)) {\n  throw new IllegalArgumentException(\"Name in use by table: \" + identifier);\n}","typeGuard":null,"tryCatchPattern":"try {\n  catalog.buildView(id)...create();\n} catch (AlreadyExistsException e) {\n  // surface 'name in use' to the user or pick a different name\n}","preventionTips":["Check tableExists/viewExists before creating objects with reused names","Drop stale tables from aborted jobs in shared environments","Namespace your identifiers (job/owner prefix) to reduce collisions"],"tags":["jdbc","name-collision","already-exists","view-creation"],"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"}