Skip to content

Commit

Permalink
feat: Support placeholders in OFFSET, FETCH ...
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Feb 23, 2024
1 parent b7f265a commit 347f769
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,7 @@ impl<'a> Parser<'a> {
pub fn parse_number_value(&mut self) -> Result<Value, ParserError> {
match self.parse_value()? {
v @ Value::Number(_, _) => Ok(v),
v @ Value::Placeholder(_) => Ok(v),
_ => {
self.prev_token();
self.expected("literal number", self.peek_token())
Expand Down Expand Up @@ -4478,7 +4479,7 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::ALL) {
Ok(None)
} else {
Ok(Some(self.parse_expr()?))
Ok(Some(Expr::Value(self.parse_number_value()?)))
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4852,6 +4852,20 @@ fn test_placeholder() {
ast.limit,
Some(Expr::Value(Value::Placeholder("$1".into())))
);

let sql = "SELECT * FROM student OFFSET $1";
let ast = dialects.verified_query(sql);
assert_eq!(
ast.offset.map(|offset| offset.value),
Some(Expr::Value(Value::Placeholder("$1".into())))
);

let sql = "SELECT * FROM student FETCH FIRST $1 ROWS ONLY";
let ast = dialects.verified_query(sql);
assert_eq!(
ast.fetch.map(|fetch| fetch.quantity),
Some(Some(Expr::Value(Value::Placeholder("$1".into()))))
);
}

#[test]
Expand Down

0 comments on commit 347f769

Please sign in to comment.