Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20848,7 +20848,16 @@ impl<'a> Parser<'a> {
/// Parse a window specification.
pub fn parse_window_spec(&mut self) -> Result<WindowSpec, ParserError> {
let window_name = match &self.peek_token_ref().token {
Token::Word(word) if word.keyword == Keyword::NoKeyword => {
Token::Word(w)
if !matches!(
w.keyword,
Keyword::PARTITION
| Keyword::ORDER
| Keyword::ROWS
| Keyword::RANGE
| Keyword::GROUPS
) =>
{
self.parse_optional_ident()?
}
_ => None,
Expand Down
21 changes: 21 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20803,3 +20803,24 @@ fn display_nested_unary_minus_in_linear_time() {
.expect("display should not take exponential time");
assert_eq!(printed, sql);
}

#[test]
fn parse_window_spec_keyword_base_window_name() {
let dialects = all_dialects();
for name in ["w", "id", "part"] {
let sql = format!("SELECT count(*) OVER ({name} ORDER BY a) FROM t");
let select = dialects.verified_only_select(&sql);
match expr_from_projection(&select.projection[0]) {
Expr::Function(Function {
over: Some(WindowType::WindowSpec(spec)),
..
}) => assert_eq!(spec.window_name, Some(Ident::new(name)), "{sql}"),
other => panic!("{sql}: unexpected {other:?}"),
}
}
dialects.verified_stmt("SELECT count(*) OVER (ORDER BY a) FROM t");
dialects.verified_stmt("SELECT count(*) OVER (PARTITION BY a) FROM t");
dialects.verified_stmt(
"SELECT count(*) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t",
);
}
Loading