risingwavelabs/risingwave · error

The database name '{}' in FROM clause does not match the dat

Error message

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.

What it means

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.

Source

Thrown at src/frontend/src/handler/create_table.rs:1056

            SQL_SERVER_CDC_CONNECTOR => {
                // SQL Server external table name must be in one of two formats:
                // 1. 'schemaName.tableName' (2 parts) - database is already specified in source
                // 2. 'databaseName.schemaName.tableName' (3 parts) - for explicit verification
                //
                // We do NOT allow single table name (e.g., 't') because:
                // - Unlike database name (already in source), schema name is NOT pre-specified
                // - User must explicitly provide schema (even if it's 'dbo')
                let parts: Vec<&str> = external_table_name.split('.').collect();
                let (schema_name, table_name) = match parts.len() {
                    3 => {
                        // Format: database.schema.table
                        // Verify that the database name matches the one in source definition
                        let db_name = parts[0];
                        let schema_name = parts[1];
                        let table_name = parts[2];

                        if db_name != source_database_name {
                            return Err(anyhow!(
                                "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.",
                                db_name,
                                source_database_name
                            ).into());
                        }
                        (schema_name, table_name)
                    }
                    2 => {
                        // Format: schema.table (recommended)
                        // Database name is taken from source definition
                        let schema_name = parts[0];
                        let table_name = parts[1];
                        (schema_name, table_name)
                    }
                    1 => {
                        // Format: table only
                        // Reject with clear error message

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Use the 2-part `schema.table` form (recommended): `FROM pg_src TABLE 'public.orders'`.
  2. Or keep the 3-part form but make the database prefix identical to the source's `database.name` value.
  3. Recreate the source with the correct `database.name` if the upstream database is actually the one in the FROM clause.

Example fix

-- before (source database.name='mydb')
CREATE TABLE t FROM pg_src TABLE 'otherdb.public.orders';
-- after
CREATE TABLE t FROM pg_src TABLE 'public.orders';
Defensive patterns

Strategy: validation

Validate before calling

fn normalize_pg_from_name(name: &str, source_db: &str) -> Result<String, String> {
    let parts: Vec<&str> = name.split('.').collect();
    match parts.len() {
        2 => Ok(name.to_string()),
        3 if parts[0] == source_db => Ok(format!("{}.{}", parts[1], parts[2])),
        3 => Err(format!("database '{}' does not match source '{}'", parts[0], source_db)),
        _ => Err("expected 'schema.table' or 'database.schema.table'".into()),
    }
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/8102bce199f104c0. Report an issue: GitHub.