Repository: diesel-rs/diesel (language: rust)

Issue:
ASC/DESC postfix operators include trailing whitespace
## Setup

### Versions

- **Rust:** 1.79.0
- **Diesel:** master
- **Database:** SQLite, MySQL, Postgres
- **Operating System**: macOS

### Feature Flags

- **diesel:** sqlite,mysql_backend,postgres_backend

## Problem Description

The generated queries for `ORDER BY` have `ASC` and `DESC` clauses with additional whitespace. This applies to the SQLite, MySQL, and Postgres backends.

### What is the expected output?

```
SQLite:
SELECT `users`.`id`, `users`.`name` FROM `users` ORDER BY `users`.`name` ASC, `users`.`id` DESC -- binds: []
MySQL:
SELECT `users`.`id`, `users`.`name` FROM `users` ORDER BY `users`.`name` ASC, `users`.`id` DESC -- binds: []
Postgres:
SELECT "users"."id", "users"."name" FROM "users" ORDER BY "users"."name" ASC, "users"."id" DESC -- binds: []
```

### What is the actual output?

```
SQLite:
SELECT `users`.`id`, `users`.`name` FROM `users` ORDER BY `users`.`name` ASC , `users`.`id` DESC  -- binds: []
MySQL:
SELECT `users`.`id`, `users`.`name` FROM `users` ORDER BY `users`.`name` ASC , `users`.`id` DESC  -- binds: []
Postgres:
SELECT "users"."id", "users"."name" FROM "users" ORDER BY "users"."name" ASC , "users"."id" DESC  -- binds: []
```

### Are you seeing any additional errors?

No.

### Steps to reproduce

Here is a full example that reproduces the output above:

```rust
use diesel::{
    backend::Backend, debug_query, mysql::Mysql, pg::Pg, prelude::*, query_builder::QueryFragment,
    sqlite::Sqlite,
};

table! {
    users {
        id -> Integer,
        name -> VarChar,
    }
}

fn main() {
    use self::users::dsl::*;

    let query = users.select((id, name)).order((name.asc(), id.desc()));

    println!("SQLite:\n{}", debug_query::<Sqlite, _>(&query));
    println!("MySQL:\n{}", debug_query::<Mysql, _>(&query));
    println!("Postgres:\n{}", debug_query::<Pg, _>(&query));
}
```

## Checklist

- [x] I have already looked over the [issue tracker](https://github.com/diesel-rs/diesel/issues) and the [discussion forum](https://github.com/diesel-rs/diesel/discussions) for similar possible closed issues.
- [x] This issue can be reproduced on Rust's stable channel. (Your issue will be
  closed if this is not the case)
- [x] This issue can be reproduced without requiring a third party crate


Discussion / hints:

Fix patch:
diff --git a/diesel/src/expression/operators.rs b/diesel/src/expression/operators.rs
index 836389908ae6..5cc9e5db83d5 100644
--- a/diesel/src/expression/operators.rs
+++ b/diesel/src/expression/operators.rs
@@ -540,12 +540,12 @@ postfix_operator!(IsNull, " IS NULL");
 postfix_operator!(IsNotNull, " IS NOT NULL");
 postfix_operator!(
     Asc,
-    " ASC ",
+    " ASC",
     crate::expression::expression_types::NotSelectable
 );
 postfix_operator!(
     Desc,
-    " DESC ",
+    " DESC",
     crate::expression::expression_types::NotSelectable
 );
 
diff --git a/examples/mysql/all_about_inserts/src/lib.rs b/examples/mysql/all_about_inserts/src/lib.rs
index 39ba19f7cd89..e5e44cd95353 100644
--- a/examples/mysql/all_about_inserts/src/lib.rs
+++ b/examples/mysql/all_about_inserts/src/lib.rs
@@ -320,7 +320,7 @@ fn examine_sql_from_insert_get_results_batch() {
                     `users`.`hair_color`, `users`.`created_at`, \
                     `users`.`updated_at` \
                     FROM `users` \
-                    ORDER BY `users`.`id` DESC  \
+                    ORDER BY `users`.`id` DESC \
                     -- binds: []";
     assert_eq!(load_sql, debug_query::<Mysql, _>(&load_query).to_string());
 }
@@ -372,7 +372,7 @@ fn examine_sql_from_insert_get_result() {
                     `users`.`hair_color`, `users`.`created_at`, \
                     `users`.`updated_at` \
                     FROM `users` \
-                    ORDER BY `users`.`id` DESC  \
+                    ORDER BY `users`.`id` DESC \
                     -- binds: []";
     assert_eq!(load_sql, debug_query::<Mysql, _>(&load_query).to_string());
 }
@@ -399,7 +399,7 @@ fn examine_sql_from_explicit_returning() {
         debug_query::<Mysql, _>(&insert_query).to_string()
     );
     let load_query = users.select(id).order(id.desc());
-    let load_sql = "SELECT `users`.`id` FROM `users` ORDER BY `users`.`id` DESC  -- binds: []";
+    let load_sql = "SELECT `users`.`id` FROM `users` ORDER BY `users`.`id` DESC -- binds: []";
     assert_eq!(load_sql, debug_query::<Mysql, _>(&load_query).to_string());
 }
 


Test patch: