clockworklabs/SpacetimeDB · error · anyhow::Error

Too many positional arguments for interactive mode. Usage…

Error message

Too many positional arguments for interactive mode.
Usage: spacetime sql [database] --interactive [--no-config]

What it means

`spacetime sql --interactive` (REPL mode) accepts at most one positional argument -- the optional database name -- because statements are typed inside the REPL. This error fires when two or more positional arguments were supplied, e.g. a database name plus a SQL string.

Solutions

  1. Drop the extra positional: `spacetime sql mydb -i`, then type statements in the REPL.
  2. To run a single statement non-interactively, remove --interactive: `spacetime sql mydb "SELECT ...".

Example fix

# before
spacetime sql mydb "SELECT * FROM t" --interactive
# after
spacetime sql mydb --interactive
# or non-interactive one-shot
spacetime sql mydb "SELECT * FROM t"
Defensive patterns

Strategy: validation

Validate before calling

# Validate argv shape before spawning the CLI
if [[ "$INTERACTIVE" == "1" && $# -gt 1 ]]; then
  echo "error: interactive sql accepts at most one positional (the database)" >&2; exit 2
fi
spacetime sql "$@"

Prevention

When it happens

Trigger: Any invocation combining --interactive with more than one positional token, such as `spacetime sql mydb "SELECT 1" -i` or `spacetime sql a b -i`.

Common situations: Copy-pasting a non-interactive `spacetime sql <db> "<query>"` line and appending -i; shell aliases or wrappers that inject extra positional arguments.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-08-20). Data as JSON: /api/errors/ab9309fea7dc1cf4. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/subcommands/sql.rs:231

    )?;

    Ok((stats, table))
}

pub async fn exec(config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
    eprintln!("{UNSTABLE_WARNING}\n");
    let interactive = args.get_one::<bool>("interactive").unwrap_or(&false);
    let no_config = args.get_flag("no_config");
    let format = *args.get_one::<Format>("format").unwrap();
    let raw_parts: Vec<String> = args
        .get_many::<String>("sql_parts")
        .map(|vals| vals.cloned().collect())
        .unwrap_or_default();
    let config_targets = load_config_db_targets(no_config)?;

    if *interactive {
        if raw_parts.len() > 1 {
            anyhow::bail!(
                "Too many positional arguments for interactive mode.\nUsage: spacetime sql [database] --interactive [--no-config]"
            );
        }
        let resolved = resolve_database_arg(
            raw_parts.first().map(|s| s.as_str()),
            config_targets.as_deref(),
            "spacetime sql [database] --interactive [--no-config]",
        )?;
        let con = parse_req(config, args, &resolved.database, resolved.server.as_deref()).await?;

        crate::repl::exec(con, format).await?;
    } else {
        let resolved = resolve_optional_database_parts(
            &raw_parts,
            config_targets.as_deref(),
            "query",
            "spacetime sql [database] <query> [--no-config]",
        )

View on GitHub (pinned to eddf9f5014)