diff --git a/e2e_test/batch/order/negative_offset.slt.part b/e2e_test/batch/order/negative_offset.slt.part index 88c5c47ed15a2..38dadc4e1fa11 100644 --- a/e2e_test/batch/order/negative_offset.slt.part +++ b/e2e_test/batch/order/negative_offset.slt.part @@ -15,6 +15,34 @@ SELECT * FROM generate_series(0,10,1) LIMIT -3; statement error SELECT * FROM generate_series(0,10,1) LIMIT -1%; +statement ok +SELECT * FROM generate_series(0,10,1) as t(v) order by v limit 1+2; +---- +0 +1 +2 + + +statement ok +SELECT * FROM generate_series(0,10,1) as t(v) order by v limit 1.5*2; +--- +0 +1 +2 + + +statement ok +SELECT * FROM generate_series(0,10,1) as t(v) order by v limit -3+4; +--- +0 + +statement ok +SELECT * FROM generate_series(0,10,1) as t(v) order by v limit 1.5*2 OFFSET 2; +--- +2 +3 +4 + statement ok CREATE TABLE integers(k int); diff --git a/src/frontend/src/binder/query.rs b/src/frontend/src/binder/query.rs index c7a1118662f6c..ab1de8e625ba1 100644 --- a/src/frontend/src/binder/query.rs +++ b/src/frontend/src/binder/query.rs @@ -174,7 +174,7 @@ impl Binder { ) => { with_ties = fetch_with_ties; match quantity { - Some(v) => Some(v), + Some(v) => Some(Expr::Value(Value::Number(v))), None => Some(Expr::Value(Value::Number("1".to_owned()))), } } diff --git a/src/sqlparser/src/ast/query.rs b/src/sqlparser/src/ast/query.rs index 310b9ceb882d2..925023dfa0466 100644 --- a/src/sqlparser/src/ast/query.rs +++ b/src/sqlparser/src/ast/query.rs @@ -655,7 +655,7 @@ impl fmt::Display for OrderByExpr { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Fetch { pub with_ties: bool, - pub quantity: Option, + pub quantity: Option, } impl fmt::Display for Fetch { diff --git a/src/sqlparser/src/parser.rs b/src/sqlparser/src/parser.rs index 6fde45db9148e..7f3bf98f9d247 100644 --- a/src/sqlparser/src/parser.rs +++ b/src/sqlparser/src/parser.rs @@ -5362,7 +5362,7 @@ impl Parser<'_> { { None } else { - let quantity = self.parse_expr()?; + let quantity = self.parse_number_value()?; self.expect_one_of_keywords(&[Keyword::ROW, Keyword::ROWS])?; Some(quantity) }; diff --git a/src/sqlparser/tests/sqlparser_common.rs b/src/sqlparser/tests/sqlparser_common.rs index 9ce0b620bf963..9018a4f00510b 100644 --- a/src/sqlparser/tests/sqlparser_common.rs +++ b/src/sqlparser/tests/sqlparser_common.rs @@ -3551,7 +3551,7 @@ fn parse_fetch() { let fetch_first_two_rows_only = Some(Fetch { with_ties: false, - quantity: Some(Expr::Value(Value::Number("2".to_owned()))), + quantity: Some("2".to_owned()), }); let ast = verified_query("SELECT foo FROM bar FETCH FIRST 2 ROWS ONLY"); assert_eq!(ast.fetch, fetch_first_two_rows_only); @@ -3576,7 +3576,7 @@ fn parse_fetch() { ast.fetch, Some(Fetch { with_ties: true, - quantity: Some(Expr::Value(Value::Number("2".to_owned()))), + quantity: Some("2".to_owned()), }) ); let ast = verified_query(