{"record":{"id":"35c2a0d476cea053","repo":"clockworklabs/SpacetimeDB","slug":"multiple-databases-found-in-config-please-spe-35c2a0","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/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/src/subcommands/sql.rs#L247-L283","documentation":"From `spacetime sql` argument resolution: you passed a single argument that contains a space (almost certainly the SQL query, so no positional database can be inferred), and the project/config exposes more than one database target, so the CLI cannot pick a default. It lists the known databases and echoes your query back in the suggested command.","triggerScenarios":"`spacetime sql \"SELECT * FROM t\"` (query only, no database) while the detected project config declares multiple database targets; any one-argument invocation whose argument contains a space when config_targets has 2+ entries.","commonSituations":"Monorepos/workspaces with several databases in one project; switching between databases in the same checkout; CI scripts written when only one database existed and later a second was added.","solutions":["Name the database explicitly: `spacetime sql <database> \"SELECT ...\"` exactly as printed in the error","Reduce the project config to a single default database if one is canonical","In scripts, always pass <database> positionally instead of relying on auto-detection"],"exampleFix":"# before\nspacetime sql \"SELECT * FROM player\"\n\n# after\nspacetime sql my_game \"SELECT * FROM player\"","handlingStrategy":"validation","validationCode":"# bash: always pass the database positionally in scripts\nDB=\"${SPACETIME_DB:?set SPACETIME_DB to the target database}\"\nspacetime sql \"$DB\" \"SELECT * FROM player\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never rely on single-database auto-detection in projects that declare multiple targets","Set an explicit default database in spacetime.json for interactive use, and pass <database> explicitly in CI"],"tags":["cli","sql","config","argument-parsing"],"backgroundTag":"ambiguous-database-target","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}