{"record":{"id":"9de06fb776369a31","repo":"apache/iceberg","slug":"table-s-already-exists-in-the-database-s-and-cat-9de06f","errorCode":null,"errorMessage":"Table %s already exists in the database %s and catalog %s","messagePattern":"Table (.+?) already exists in the database (.+?) and catalog (.+?)","errorType":"exception","errorClass":"org.apache.flink.table.catalog.exceptions.AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkDynamicTableFactory.java","lineNumber":226,"sourceCode":"    if (!flinkCatalog.databaseExists(catalogDatabase)) {\n      try {\n        flinkCatalog.createDatabase(\n            catalogDatabase, new CatalogDatabaseImpl(Maps.newHashMap(), null), true);\n      } catch (DatabaseAlreadyExistException e) {\n        throw new AlreadyExistsException(\n            e,\n            \"Database %s already exists in the iceberg catalog %s.\",\n            catalogName,\n            catalogDatabase);\n      }\n    }\n\n    // Create table if not exists in the external catalog.\n    if (!flinkCatalog.tableExists(objectPath)) {\n      try {\n        flinkCatalog.createIcebergTable(objectPath, resolvedCatalogTable, true);\n      } catch (TableAlreadyExistException e) {\n        throw new AlreadyExistsException(\n            e,\n            \"Table %s already exists in the database %s and catalog %s\",\n            catalogTable,\n            catalogDatabase,\n            catalogName);\n      }\n    }\n\n    return TableLoader.fromCatalog(\n        flinkCatalog.getCatalogLoader(), TableIdentifier.of(catalogDatabase, catalogTable));\n  }\n\n  /**\n   * Merges source catalog properties (catalog name, database, table) with connector properties.\n   * Source catalog name, database, table are serialized as json in FlinkCatalog#getTable to be able\n   * to isolate them from iceberg table props, Here, we flatten and merge them back.\n   *\n   * @param tableProps the existing table properties","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkDynamicTableFactory.java#L208-L244","documentation":"createTableLoader checks tableExists and then attempts createIcebergTable with ignoreIfExists semantics. If TableAlreadyExistException is thrown anyway (e.g., concurrent creation), it is wrapped into AlreadyExistsException with 'Table %s already exists in the database %s and catalog %s'.","triggerScenarios":"Concurrent CREATE TABLE (or Flink dynamic table source/sink initialization) for the same Iceberg table from multiple jobs; check-then-create race between tableExists and createIcebergTable.","commonSituations":"Two streaming jobs writing to the same table path launched simultaneously; CI pipelines deploying the same job twice; shared dev catalogs where tables are created ad hoc.","solutions":["Check flinkCatalog.tableExists(objectPath) first and reuse the existing table","Catch AlreadyExistsException and treat as success when the existing table matches your schema","Serialize table creation via deployment orchestration","Use unique table names per job/environment"],"exampleFix":"// before\nflinkCatalog.createIcebergTable(objectPath, resolvedCatalogTable, true);\n\n// after\nif (!flinkCatalog.tableExists(objectPath)) {\n  flinkCatalog.createIcebergTable(objectPath, resolvedCatalogTable, true);\n}","handlingStrategy":"try-catch","validationCode":"if (!catalog.tableExists(objectPath)) { /* create */ }","typeGuard":null,"tryCatchPattern":"try { catalog.createIcebergTable(objectPath, tbl, true); } catch (TableAlreadyExistException | AlreadyExistsException e) { /* idempotent success */ }","preventionTips":["Check tableExists before creating","Treat AlreadyExistsException as success when schema matches","Serialize table creation in deployment pipelines","Use unique table names per environment"],"tags":["flink","catalog","table-exists","race-condition"],"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"}