diff --git a/src/parser.rs b/src/parser.rs index e8c9822dc..238997200 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2906,6 +2906,7 @@ impl<'a> Parser<'a> { pub fn parse_number_value(&mut self) -> Result { match self.parse_value()? { v @ Value::Number(_, _) => Ok(v), + v @ Value::Placeholder(_) => Ok(v), _ => { self.prev_token(); self.expected("literal number", self.peek_token()) @@ -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()?))) } } diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 63f826bd4..840db83c7 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -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]