Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT sum(x) OVER (ORDER BY f RANGE BETWEEN 'inf' PRECEDING AND '1 day' FOLLOWING) FROM t;
5 changes: 1 addition & 4 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2794,10 +2794,7 @@ impl<'a> Parser<'a> {
let rows = if self.parse_keyword(Keyword::UNBOUNDED) {
None
} else {
Some(Box::new(match &self.peek_token_ref().token {
Token::SingleQuotedString(_) => self.parse_interval()?,
_ => self.parse_expr()?,
}))
Some(Box::new(self.parse_expr()?))
};
if self.parse_keyword(Keyword::PRECEDING) {
Ok(WindowFrameBound::Preceding(rows))
Expand Down
48 changes: 48 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23323,3 +23323,51 @@ fn display_refresh_materialized_view_propagates_write_errors() {
assert_eq!(write!(writer, "{statement}"), Err(fmt::Error), "{rejected}");
}
}

#[test]
fn parse_window_frame_untyped_string_offset() {
let dialects = all_dialects_except(|d| d.require_interval_qualifier());
dialects.verified_stmt(
"SELECT sum(x) OVER (ORDER BY f RANGE BETWEEN 'inf' PRECEDING AND '1 day' FOLLOWING) FROM t",
);
dialects.verified_stmt(
"SELECT sum(x) OVER (ORDER BY f ROWS BETWEEN 'hello' PRECEDING AND 10 FOLLOWING) FROM t",
);
assert_eq!(
dialects
.parse_sql_statements(
"SELECT sum(x) OVER (ORDER BY f ROWS BETWEEN ) PRECEDING AND CURRENT ROW) FROM t"
)
.unwrap_err(),
ParserError::ParserError("Expected: an expression, found: )".to_string())
);

let select = dialects.verified_only_select(
"SELECT sum(x) OVER (ORDER BY f RANGE BETWEEN INTERVAL '1' DAY PRECEDING AND CURRENT ROW) FROM t",
);
match expr_from_projection(&select.projection[0]) {
Expr::Function(Function { over, .. }) => match over.as_ref() {
Some(WindowType::WindowSpec(WindowSpec {
window_frame: Some(frame),
..
})) => assert_eq!(
frame,
&WindowFrame {
units: WindowFrameUnits::Range,
start_bound: WindowFrameBound::Preceding(Some(Box::new(Expr::Interval(
Interval {
value: Box::new(Expr::value(Value::SingleQuotedString("1".to_owned()))),
leading_field: Some(DateTimeField::Day),
leading_precision: None,
last_field: None,
fractional_seconds_precision: None,
},
)))),
end_bound: Some(WindowFrameBound::CurrentRow),
}
),
_ => panic!("expected a window specification"),
},
_ => panic!("expected a window function"),
}
}
Loading