{"record":{"id":"39f3d44b17a069b9","repo":"risingwavelabs/risingwave","slug":"object-type-named-name-already-exists","errorCode":null,"errorMessage":"{object_type} named {name} already exists{}","messagePattern":"(.+?) named (.+?) already exists(.+?)","errorType":"error_code","errorClass":"CatalogError","httpStatus":null,"severity":"error","filePath":"src/frontend/src/catalog/mod.rs","lineNumber":117,"sourceCode":"        )).into())\n    } else {\n        Ok(())\n    }\n}\n\npub type CatalogResult<T> = std::result::Result<T, CatalogError>;\n\n// TODO(error-handling): provide more concrete error code for different object types.\n#[derive(Error, Debug, thiserror_ext::Box)]\n#[thiserror_ext(newtype(name = CatalogError, extra_provide = Self::provide_postgres_error_code))]\npub enum CatalogErrorInner {\n    #[error(\"{object_type} not found: {name}\")]\n    NotFound {\n        object_type: &'static str,\n        name: String,\n    },\n\n    #[error(\n        \"{object_type} named {name} already exists{}\",\n        if *.under_creation { \" and is still being created\" } else { \"\" },\n    )]\n    Duplicated {\n        object_type: &'static str,\n        name: String,\n        under_creation: bool, // only used for StreamingJob type and Subscription for now\n    },\n}\n\nimpl CatalogError {\n    /// Provide the Postgres error code for the error.\n    fn provide_postgres_error_code(&self, request: &mut std::error::Request<'_>) {\n        match self.inner() {\n            CatalogErrorInner::NotFound { object_type, .. } => {\n                // `database` not found should map to SQLSTATE 3D000 (Invalid Catalog Name),\n                // which is used by Postgres for non-existing database in startup.\n                if *object_type == \"database\" {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/catalog/mod.rs#L99-L135","documentation":"CatalogError::Duplicated is raised when creating a catalog object whose name already exists. It additionally reports whether the existing object is `under_creation` (still being created), which appends \" and is still being created\" to the message.","triggerScenarios":"`CREATE TABLE`/`CREATE MATERIALIZED VIEW`/`CREATE SOURCE` with a name that already exists in the schema; retrying a creation whose first attempt is still in-flight (the name is registered but creation is incomplete).","commonSituations":"Re-running idempotency-unaware migration scripts; concurrent jobs or deployments creating the same object name; retry after a failed creation that left the name registered as under-creation.","solutions":["Choose a different name or drop the existing object first (`DROP TABLE/MATERIALIZED VIEW <name>`).","Use `CREATE ... IF NOT EXISTS` where supported to tolerate pre-existing objects.","If the message says the object is still being created, wait for the ongoing creation to finish (or clean up the stuck object) before retrying."],"exampleFix":"-- before\nCREATE MATERIALIZED VIEW mv AS SELECT ...;\n-- after\nDROP MATERIALIZED VIEW IF EXISTS mv;\nCREATE MATERIALIZED VIEW mv AS SELECT ...;","handlingStrategy":"try-catch","validationCode":"const dup = await client.query(\n  \"SELECT 1 FROM rw_tables WHERE name = $1\", [name]);\nif (dup.rows.length > 0) throw new Error(`name ${name} already in use`);","typeGuard":"function nameIsFree(rows) { return Array.isArray(rows) && rows.length === 0; }","tryCatchPattern":"try {\n  await client.query(`CREATE MATERIALIZED VIEW ${mv} AS ...`);\n} catch (e) {\n  if (String(e.message).includes(\"already exists\")) {\n    // drop and recreate, or reuse the existing object\n  } else throw e;\n}","preventionTips":["Use IF NOT EXISTS for idempotent DDL scripts","Serialize concurrent creations of the same name in deployment tooling","On retries after failure, wait for or clean up objects stuck 'under creation'"],"tags":["catalog","duplicate","ddl","frontend"],"backgroundTag":"file-already-exists","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}