{"record":{"id":"a1a699bdb44da95d","repo":"apache/iceberg","slug":"table-already-exists-s-a1a699","errorCode":null,"errorMessage":"Table already exists: %s","messagePattern":"Table already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":409,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java","lineNumber":412,"sourceCode":"  }\n\n  public static ListTablesResponse listTables(\n      Catalog catalog, Namespace namespace, String pageToken, String pageSize) {\n    List<TableIdentifier> results = catalog.listTables(namespace);\n\n    Pair<List<TableIdentifier>, String> page =\n        paginate(results, pageToken, Integer.parseInt(pageSize));\n\n    return ListTablesResponse.builder().addAll(page.first()).nextPageToken(page.second()).build();\n  }\n\n  public static LoadTableResponse stageTableCreate(\n      Catalog catalog, Namespace namespace, CreateTableRequest request) {\n    request.validate();\n\n    TableIdentifier ident = TableIdentifier.of(namespace, request.name());\n    if (catalog.tableExists(ident)) {\n      throw new AlreadyExistsException(\"Table already exists: %s\", ident);\n    }\n\n    Map<String, String> properties = Maps.newHashMap();\n    properties.put(\"created-at\", OffsetDateTime.now(ZoneOffset.UTC).toString());\n    properties.putAll(request.properties());\n\n    String location;\n    if (request.location() != null) {\n      location = request.location();\n    } else {\n      location =\n          catalog\n              .buildTable(ident, request.schema())\n              .withPartitionSpec(request.spec())\n              .withSortOrder(request.writeOrder())\n              .withProperties(properties)\n              .createTransaction()\n              .table()","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java#L394-L430","documentation":"CatalogHandlers.stageTableCreate rejects a create-table request with AlreadyExistsException when a table with the same identifier already exists (catalog.tableExists check). Staged creates refuse to clobber existing tables; this maps to a 409-style conflict in REST semantics.","triggerScenarios":"Calling createTable/stageTableCreate (REST POST v1/namespaces/{ns}/tables) when a table with namespace + request.name() already exists.","commonSituations":"Retried requests after a first successful create; concurrent jobs creating the same table; re-running setup scripts without create-or-replace semantics.","solutions":["Check tableExists before creating, or catch AlreadyExistsException and reuse the table","Use create-or-replace / create-or-ignore transaction semantics if intended","Use unique (timestamped/suffixed) table names for repeated pipelines","Find the duplicate request source (retries, schedulers) causing double creates"],"exampleFix":"// before\nTable t = catalog.createTable(ident, schema); // throws if exists\n// after\nTable t = catalog.tableExists(ident)\n    ? catalog.loadTable(ident)\n    : catalog.createTable(ident, schema);","handlingStrategy":"try-catch","validationCode":"if (catalog.tableExists(ident)) {\n  // load or skip\n} else {\n  catalog.createTable(ident, schema);\n}","typeGuard":null,"tryCatchPattern":"try {\n  catalog.createTable(ident, schema);\n} catch (AlreadyExistsException e) {\n  table = catalog.loadTable(ident);\n}","preventionTips":["Make table creation idempotent with exists-checks or create-or-replace","Serialize setup jobs that create the same table","Use deterministic table names in CI pipelines"],"tags":["rest-catalog","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"}