{"record":{"id":"11a04557534843eb","repo":"apache/iceberg","slug":"namespace-already-exists-s-11a045","errorCode":null,"errorMessage":"Namespace already exists: %s","messagePattern":"Namespace already exists: (.+?)","errorType":"exception","errorClass":"AlreadyExistsException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":416,"sourceCode":"          \"Rename operation affected {} rows: the catalog table's primary key assumption has been violated\",\n          updatedRecords);\n    }\n  }\n\n  @Override\n  public String name() {\n    return catalogName;\n  }\n\n  @Override\n  public void setConf(Object conf) {\n    this.conf = conf;\n  }\n\n  @Override\n  public void createNamespace(Namespace namespace, Map<String, String> metadata) {\n    if (namespaceExists(namespace)) {\n      throw new AlreadyExistsException(\"Namespace already exists: %s\", namespace);\n    }\n\n    Map<String, String> createMetadata;\n    if (metadata == null || metadata.isEmpty()) {\n      createMetadata = ImmutableMap.of(NAMESPACE_EXISTS_PROPERTY, \"true\");\n    } else {\n      createMetadata =\n          ImmutableMap.<String, String>builder()\n              .putAll(metadata)\n              .put(NAMESPACE_EXISTS_PROPERTY, \"true\")\n              .buildOrThrow();\n    }\n\n    insertProperties(namespace, createMetadata);\n  }\n\n  @Override\n  public List<Namespace> listNamespaces() {","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L398-L434","documentation":"createNamespace throws AlreadyExistsException when the namespace already exists in the JDBC catalog. The check runs before inserting the namespace metadata row. Namespaces are stored as rows in the catalog tables, so duplicates violate the uniqueness contract of the Catalog API.","triggerScenarios":"Calling catalog.createNamespace(namespace, metadata) where catalog.namespaceExists(namespace) returns true.","commonSituations":"Initialization scripts run twice; concurrent creation of the same namespace by multiple clients; re-running setup after a partial bootstrap that already created the namespace.","solutions":["Check catalog.namespaceExists(ns) before creating, or skip on AlreadyExistsException","Use namespaceExists as an idempotency guard in setup scripts","If the existing namespace is unwanted, drop it first (it must be empty) then recreate"],"exampleFix":"// before\ncatalog.createNamespace(ns);\n// after\nif (!catalog.namespaceExists(ns)) {\n  catalog.createNamespace(ns);\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["jdbc-catalog","already-exists","namespace"],"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-14T21:17:11.552Z"}