Skip to content

Commit a926460

Browse files
committed
Add missing parenthesis to window definition (#919)
<!-- Thank you for contributing to this project! If you need any help please feel free to contact us on Discord: https://discord.com/invite/uCPdDXzbdv Or, mention our core members by typing `@GitHub_Handle` on any issue / PR Add some test cases! It help reviewers to understand the behaviour and prevent it to be broken in the future. --> <!-- mention the related issue --> - Closes #764 <!-- is this PR depends on other PR? (if applicable) --> - Dependencies: - <!-- PR link --> <!-- any PR depends on this PR? (if applicable) --> - Dependents: - <!-- PR link --> - [ ] <!-- what are the new features? --> - [x] Add missing parenthesis to window_definition - [ ] <!-- any change in behaviour or method signature? is it backward compatible? --> - [ ] <!-- any other non-breaking changes to the codebase --> --- In addition, I noticed that the current SelectStatement does not support multiple windows
1 parent d6d8b24 commit a926460

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## 0.32.7 - pending
9+
10+
### Bug Fixes
11+
12+
* Fix incorrect casting of `ChronoDateTimeWithTimeZone` in `Value::Array` https://github.com/SeaQL/sea-query/pull/933
13+
* Add missing parenthesis to `WINDOW` clause https://github.com/SeaQL/sea-query/pull/919
14+
815
## 0.32.6 - 2025-05-27
916

1017
### Enhancements
1118

12-
* impl From<Condition> and From<ConditionExpression> for SimpleExpr https://github.com/SeaQL/sea-query/pull/886
19+
* impl `From<Condition>` and `From<ConditionExpression>` for `SimpleExpr` https://github.com/SeaQL/sea-query/pull/886
1320

1421
## 0.32.5 - 2025-05-07
1522

@@ -236,7 +243,7 @@ assert_eq!(
236243

237244
### New Features
238245

239-
* Construct Postgres query with vector extension https://github.com/SeaQL/sea-query/pull/774
246+
* Construct Postgres query with vector extension https://github.com/SeaQL/sea-query/pull/774
240247
* Added `postgres-vector` feature flag
241248
* Added `Value::Vector`, `ColumnType::Vector`, `ColumnDef::vector()`, `PgBinOper::EuclideanDistance`, `PgBinOper::NegativeInnerProduct` and `PgBinOper::CosineDistance`
242249
```rust
@@ -898,7 +905,7 @@ Enum {
898905

899906
### New Features
900907

901-
* Added support `DROP COLUMN` for SQLite https://github.com/SeaQL/sea-query/pull/455
908+
* Added support `DROP COLUMN` for SQLite https://github.com/SeaQL/sea-query/pull/455
902909

903910
### Bug Fixes
904911

src/backend/query_builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ pub trait QueryBuilder:
184184
if let Some((name, query)) = &select.window {
185185
write!(sql, " WINDOW ").unwrap();
186186
name.prepare(sql.as_writer(), self.quote());
187-
write!(sql, " AS ").unwrap();
187+
write!(sql, " AS (").unwrap();
188188
self.prepare_window_statement(query, sql);
189+
write!(sql, ")").unwrap();
189190
}
190191
}
191192

src/query/select.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -729,15 +729,15 @@ impl SelectStatement {
729729
///
730730
/// assert_eq!(
731731
/// query.to_string(MysqlQueryBuilder),
732-
/// r#"SELECT `character` OVER `w` FROM `character` WINDOW `w` AS PARTITION BY `font_size`"#
732+
/// r#"SELECT `character` OVER `w` FROM `character` WINDOW `w` AS (PARTITION BY `font_size`)"#
733733
/// );
734734
/// assert_eq!(
735735
/// query.to_string(PostgresQueryBuilder),
736-
/// r#"SELECT "character" OVER "w" FROM "character" WINDOW "w" AS PARTITION BY "font_size""#
736+
/// r#"SELECT "character" OVER "w" FROM "character" WINDOW "w" AS (PARTITION BY "font_size")"#
737737
/// );
738738
/// assert_eq!(
739739
/// query.to_string(SqliteQueryBuilder),
740-
/// r#"SELECT "character" OVER "w" FROM "character" WINDOW "w" AS PARTITION BY "font_size""#
740+
/// r#"SELECT "character" OVER "w" FROM "character" WINDOW "w" AS (PARTITION BY "font_size")"#
741741
/// );
742742
/// ```
743743
pub fn expr_window_name<T, W>(&mut self, expr: T, window: W) -> &mut Self
@@ -768,15 +768,15 @@ impl SelectStatement {
768768
///
769769
/// assert_eq!(
770770
/// query.to_string(MysqlQueryBuilder),
771-
/// r#"SELECT `character` OVER `w` AS `C` FROM `character` WINDOW `w` AS PARTITION BY `font_size`"#
771+
/// r#"SELECT `character` OVER `w` AS `C` FROM `character` WINDOW `w` AS (PARTITION BY `font_size`)"#
772772
/// );
773773
/// assert_eq!(
774774
/// query.to_string(PostgresQueryBuilder),
775-
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS PARTITION BY "font_size""#
775+
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS (PARTITION BY "font_size")"#
776776
/// );
777777
/// assert_eq!(
778778
/// query.to_string(SqliteQueryBuilder),
779-
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS PARTITION BY "font_size""#
779+
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS (PARTITION BY "font_size")"#
780780
/// );
781781
/// ```
782782
pub fn expr_window_name_as<T, W, A>(&mut self, expr: T, window: W, alias: A) -> &mut Self
@@ -2430,15 +2430,15 @@ impl SelectStatement {
24302430
///
24312431
/// assert_eq!(
24322432
/// query.to_string(MysqlQueryBuilder),
2433-
/// r#"SELECT `character` OVER `w` AS `C` FROM `character` WINDOW `w` AS PARTITION BY `font_size`"#
2433+
/// r#"SELECT `character` OVER `w` AS `C` FROM `character` WINDOW `w` AS (PARTITION BY `font_size`)"#
24342434
/// );
24352435
/// assert_eq!(
24362436
/// query.to_string(PostgresQueryBuilder),
2437-
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS PARTITION BY "font_size""#
2437+
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS (PARTITION BY "font_size")"#
24382438
/// );
24392439
/// assert_eq!(
24402440
/// query.to_string(SqliteQueryBuilder),
2441-
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS PARTITION BY "font_size""#
2441+
/// r#"SELECT "character" OVER "w" AS "C" FROM "character" WINDOW "w" AS (PARTITION BY "font_size")"#
24422442
/// );
24432443
/// ```
24442444
pub fn window<A>(&mut self, name: A, window: WindowStatement) -> &mut Self

0 commit comments

Comments
 (0)