{"record":{"id":"edaf1f23b82d4f36","repo":"clockworklabs/SpacetimeDB","slug":"multiple-databases-found-in-config-please-spe-edaf1f","errorCode":null,"errorMessage":"Multiple databases found in config: {}. Please specify which database to query:\n  spacetime sql <database> \"{}\"","messagePattern":"Multiple databases found in config: (.+?)\\. Please specify which database to query:\n  spacetime sql <database> \"(.+?)\"","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/sql.rs","lineNumber":265,"sourceCode":"            \"query\",\n            \"spacetime sql [database] <query> [--no-config]\",\n        )\n        .or_else(|e| {\n            // `sql` expects exactly 1 query arg, so if we have 2+ positional args the first\n            // must be a database name. If it didn't match any config target, treat it as an\n            // ad-hoc database outside the project (auto-fallthrough).\n            if raw_parts.len() >= 2 {\n                Ok(ResolvedDbArgs {\n                    database: raw_parts[0].clone(),\n                    server: None,\n                    remaining_args: raw_parts[1..].to_vec(),\n                })\n            } else if raw_parts.len() == 1 && raw_parts[0].contains(' ') {\n                // The single arg contains spaces, so it's almost certainly a SQL query,\n                // not a database name. Give a clearer error than \"missing <query>\".\n                let targets = config_targets.as_deref().unwrap_or_default();\n                let known: Vec<&str> = targets.iter().map(|t| t.database.as_str()).collect();\n                Err(anyhow::anyhow!(\n                    \"Multiple databases found in config: {}. Please specify which database to query:\\n  \\\n                     spacetime sql <database> \\\"{}\\\"\",\n                    known.join(\", \"),\n                    raw_parts[0]\n                ))\n            } else {\n                Err(e)\n            }\n        })?;\n        let query = resolved.remaining_args.join(\" \");\n        let confirmed = args.get_one::<bool>(\"confirmed\").copied();\n\n        let con = parse_req(config, args, &resolved.database, resolved.server.as_deref()).await?;\n        let mut api = ClientApi::new(con).sql();\n        if let Some(confirmed) = confirmed {\n            api = api.query(&[(\"confirmed\", if confirmed { \"true\" } else { \"false\" })]);\n        }\n","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/sql.rs#L247-L283","documentation":"When `spacetime sql` gets exactly one positional that contains a space, it assumes the argument is a SQL query rather than a database name. It then looks at the project config database targets: if more than one database is configured and no explicit database was given, there is no way to pick a target, so it errors listing the configured database names and echoing the query back in a corrected command line.","triggerScenarios":"Running `spacetime sql \"SELECT * FROM my_table\"` from a project directory whose config declares multiple database targets, without naming which database to run against.","commonSituations":"Monorepo or workspace config with several databases (dev/test/prod); newly added second database in a project template; assuming the CLI remembers a 'current' database from a previous invocation.","solutions":["Re-run with the database name first, exactly as the message shows: `spacetime sql <database> \"<query>\"`","Set/keep a single default database in the project config so the disambiguation disappears","Use `--no-config` if you intended an ad-hoc server database rather than the project's configured targets","Tab-complete the database name to avoid typos against the names printed in the error"],"exampleFix":"# before\nspacetime sql \"SELECT * FROM player\"        # config has db1, db2\n# after\nspacetime sql db1 \"SELECT * FROM player\"","handlingStrategy":"validation","validationCode":"# Detect multi-database configs before running ad-hoc queries\nn=$(toml-get project.databases 2>/dev/null | wc -l)   # or count entries however your config is shaped\n[ \"$n\" -le 1 ] || echo 'multiple db targets: always pass <database> explicitly'","typeGuard":null,"tryCatchPattern":"// Wrapper: on the ambiguity error, surface a database picker instead of failing\nlet out = run_cli(\"spacetime sql \\\"SELECT 1\\\"\");\nif out.contains(\"Multiple databases found in config\") { pick_db_and_retry(); }","preventionTips":["Always invoke `spacetime sql <database> \"<query>\"` in projects with more than one database","Keep a single default database in project config when possible","Use `--no-config` deliberately for ad-hoc server databases"],"tags":["spacetimedb","sql","ambiguity","project-config","cli"],"backgroundTag":"ambiguous-target-database","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}