{"record":{"id":"8102bce199f104c0","repo":"risingwavelabs/risingwave","slug":"the-database-name-in-from-clause-does-not-mat","errorCode":null,"errorMessage":"The database name '{}' in FROM clause does not match the database name '{}' specified in source definition. You can either use 'schema.table' format (recommended) or ensure the database name matches.","messagePattern":"The database name '(.+?)' in FROM clause does not match the database name '(.+?)' specified in source definition\\. You can either use 'schema\\.table' format \\(recommended\\) or ensure the database name matches\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/frontend/src/handler/create_table.rs","lineNumber":1056,"sourceCode":"            SQL_SERVER_CDC_CONNECTOR => {\n                // SQL Server external table name must be in one of two formats:\n                // 1. 'schemaName.tableName' (2 parts) - database is already specified in source\n                // 2. 'databaseName.schemaName.tableName' (3 parts) - for explicit verification\n                //\n                // We do NOT allow single table name (e.g., 't') because:\n                // - Unlike database name (already in source), schema name is NOT pre-specified\n                // - User must explicitly provide schema (even if it's 'dbo')\n                let parts: Vec<&str> = external_table_name.split('.').collect();\n                let (schema_name, table_name) = match parts.len() {\n                    3 => {\n                        // Format: database.schema.table\n                        // Verify that the database name matches the one in source definition\n                        let db_name = parts[0];\n                        let schema_name = parts[1];\n                        let table_name = parts[2];\n\n                        if db_name != source_database_name {\n                            return Err(anyhow!(\n                                \"The database name '{}' in FROM clause does not match the database name '{}' specified in source definition. \\\n                                 You can either use 'schema.table' format (recommended) or ensure the database name matches.\",\n                                db_name,\n                                source_database_name\n                            ).into());\n                        }\n                        (schema_name, table_name)\n                    }\n                    2 => {\n                        // Format: schema.table (recommended)\n                        // Database name is taken from source definition\n                        let schema_name = parts[0];\n                        let table_name = parts[1];\n                        (schema_name, table_name)\n                    }\n                    1 => {\n                        // Format: table only\n                        // Reject with clear error message","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/frontend/src/handler/create_table.rs#L1038-L1074","documentation":"For Postgres/SQL Server CDC sources, the FROM-clause name is expected as `database.schema.table` (3 parts); the leading database must exactly equal the `database.name` set in the source definition. If it differs, the error suggests either using `schema.table` (letting the source's database apply) or fixing the prefix.","triggerScenarios":"`CREATE TABLE ... FROM pg_src TABLE 'otherdb.public.orders'` where the source's `database.name` is `mydb`; also hit during `generate_stream_graph_for_replace_table` on mismatched names.","commonSituations":"Copy-pasting fully-qualified names from a different environment; sources whose `database.name` was updated after table creation; users confusing database vs schema in Postgres naming.","solutions":["Use the 2-part `schema.table` form (recommended): `FROM pg_src TABLE 'public.orders'`.","Or keep the 3-part form but make the database prefix identical to the source's `database.name` value.","Recreate the source with the correct `database.name` if the upstream database is actually the one in the FROM clause."],"exampleFix":"-- before (source database.name='mydb')\nCREATE TABLE t FROM pg_src TABLE 'otherdb.public.orders';\n-- after\nCREATE TABLE t FROM pg_src TABLE 'public.orders';","handlingStrategy":"validation","validationCode":"fn normalize_pg_from_name(name: &str, source_db: &str) -> Result<String, String> {\n    let parts: Vec<&str> = name.split('.').collect();\n    match parts.len() {\n        2 => Ok(name.to_string()),\n        3 if parts[0] == source_db => Ok(format!(\"{}.{}\", parts[1], parts[2])),\n        3 => Err(format!(\"database '{}' does not match source '{}'\", parts[0], source_db)),\n        _ => Err(\"expected 'schema.table' or 'database.schema.table'\".into()),\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the 2-part schema.table form for Postgres/SQL Server CDC tables","If using 3-part names, copy database.name verbatim from the source definition","Update dependent tables when the source's database.name changes"],"tags":["rust","cdc","postgres","validation"],"backgroundTag":"invalid-argument-value","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"}