{"record":{"id":"33eb3b93ca2c950b","repo":"apache/iceberg","slug":"view-with-same-name-already-exists-s-33eb3b","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/JdbcTableOperations.java","lineNumber":176,"sourceCode":"      LOG.debug(\"Successfully committed to existing table: {}\", tableIdentifier);\n    } else {\n      throw new CommitFailedException(\n          \"Failed to update table %s from catalog %s\", tableIdentifier, catalogName);\n    }\n  }\n\n  private void createTable(String newMetadataLocation) throws SQLException, InterruptedException {\n    Namespace namespace = tableIdentifier.namespace();\n    if (PropertyUtil.propertyAsBoolean(catalogProperties, JdbcUtil.STRICT_MODE_PROPERTY, false)\n        && !JdbcUtil.namespaceExists(catalogName, connections, namespace)) {\n      throw new NoSuchNamespaceException(\n          \"Cannot create table %s in catalog %s. Namespace %s does not exist\",\n          tableIdentifier, catalogName, namespace);\n    }\n\n    if (schemaVersion == JdbcUtil.SchemaVersion.V1\n        && JdbcUtil.viewExists(catalogName, connections, tableIdentifier)) {\n      throw new AlreadyExistsException(\"View with same name already exists: %s\", tableIdentifier);\n    }\n\n    if (JdbcUtil.tableExists(schemaVersion, catalogName, connections, tableIdentifier)) {\n      throw new AlreadyExistsException(\"Table already exists: %s\", tableIdentifier);\n    }\n\n    int insertRecord =\n        JdbcUtil.doCommitCreateTable(\n            schemaVersion,\n            connections,\n            catalogName,\n            namespace,\n            tableIdentifier,\n            newMetadataLocation);\n\n    if (insertRecord == 1) {\n      LOG.debug(\"Successfully committed to new table: {}\", tableIdentifier);\n    } else {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcTableOperations.java#L158-L194","documentation":"In JDBC catalog schema V1, tables and views share the same name space in the underlying jdbc_tables record store (V1 predates the separate views table). Before creating a table, createTable checks JdbcUtil.viewExists and throws AlreadyExistsException if a view of the same name is registered, preventing silent shadowing of a view by a table.","triggerScenarios":"createTable() called for an identifier that was previously registered as a view in a V1 JDBC catalog; a table/view name collision after migrating a catalog from V0 to V1; SQL CREATE TABLE issued where a CREATE VIEW already registered the name.","commonSituations":"Legacy JDBC catalogs (schema V1) shared by engines creating both views and tables; name collisions after database consolidation; users unaware that old JDBC catalogs stored views in the table record store.","solutions":["Choose a different name for the new table, or drop the existing view (catalog.dropView) if it is no longer needed","Upgrade the JDBC catalog schema to V1 with separate view handling and confirm which entity owns the name: catalog.tableExists vs catalog.viewExists","List views in the namespace (catalog.listViews) to see the conflicting registration"],"exampleFix":"// before\nif (catalog.viewExists(ident)) { throw ...; }\ncatalog.createTable(ident, schema);\n// after\nif (catalog.viewExists(ident)) {\n  catalog.dropView(ident); // deliberate replacement\n}\ncatalog.createTable(ident, schema);","handlingStrategy":"validation","validationCode":"if (catalog.viewExists(identifier)) { throw new IllegalStateException(\"Name taken by view: \" + identifier); }","typeGuard":null,"tryCatchPattern":"try { catalog.createTable(identifier, schema); } catch (AlreadyExistsException e) { if (catalog.viewExists(identifier)) { /* resolve collision: rename or drop view */ } }","preventionTips":["Check both tableExists and viewExists before choosing names","Use naming conventions separating view and table names in shared legacy V1 catalogs","Upgrade JDBC catalog schema so views get their own record store","List views (catalog.listViews) during incident triage of name collisions"],"tags":["jdbc","views","name-collision","already-exists"],"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"}