Skip to content

Error in Command due to incorrect argument order in does_db_exist in Windows #2070

Description

@if0ne

This command:

let mut command = Command::new(pg_config.psql_path()?);
command
    .arg("-XqAt")
    .env_remove("PGUSER")
    .arg("-h")
    .arg(pg_config.host())
    .arg("-p")
    .arg(pg_config.port()?.to_string())
    .arg("template1")
    .arg("-c")
    .arg(format!(
        "select count(*) from pg_database where datname = '{}';",
        dbname.replace('\'', "''")
    ))
    .stdout(Stdio::piped())
    .stderr(Stdio::piped());

Return error:

Error:
   0: problem checking if database 'pgnats' exists: "C:/Users/alche/PGRX~1/13.21/bin\\psql.exe" "-XqAt" "-h" "localhost" "-p" "28813" "template1" "-c" "select count(*) from pg_database where datname = \'pgnats\';"

      psql: error: FATAL:  role "-c" does not exist

But here's the order of the arguments:

let mut command = Command::new(pg_config.psql_path()?);
command
    .arg("-XqAt")
    .env_remove("PGUSER")
    .arg("-h")
    .arg(pg_config.host())
    .arg("-p")
    .arg(pg_config.port()?.to_string())
    .arg("-c")
    .arg(format!(
        "select count(*) from pg_database where datname = '{}';",
        dbname.replace('\'', "''")
    ))
    .arg("template1")
    .stdout(Stdio::piped())
    .stderr(Stdio::piped());

Running successfully.

OS: Windows 11 64-bit, build 26100

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions