Skip to content

Commit 68d8d87

Browse files
committed
Make parse_fetch more permissive
1 parent 50ee50a commit 68d8d87

File tree

2 files changed

+6
-38
lines changed

2 files changed

+6
-38
lines changed

src/parser/mod.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15017,10 +15017,8 @@ impl<'a> Parser<'a> {
1501715017

1501815018
/// Parse a FETCH clause
1501915019
pub fn parse_fetch(&mut self) -> Result<Fetch, ParserError> {
15020-
if dialect_of!(self is SnowflakeDialect) {
15021-
return self.parse_snowflake_fetch();
15022-
}
15023-
self.expect_one_of_keywords(&[Keyword::FIRST, Keyword::NEXT])?;
15020+
let _ = self.parse_one_of_keywords(&[Keyword::FIRST, Keyword::NEXT]);
15021+
1502415022
let (quantity, percent) = if self
1502515023
.parse_one_of_keywords(&[Keyword::ROW, Keyword::ROWS])
1502615024
.is_some()
@@ -15029,39 +15027,23 @@ impl<'a> Parser<'a> {
1502915027
} else {
1503015028
let quantity = Expr::Value(self.parse_value()?);
1503115029
let percent = self.parse_keyword(Keyword::PERCENT);
15032-
self.expect_one_of_keywords(&[Keyword::ROW, Keyword::ROWS])?;
15030+
let _ = self.parse_one_of_keywords(&[Keyword::ROW, Keyword::ROWS]);
1503315031
(Some(quantity), percent)
1503415032
};
15033+
1503515034
let with_ties = if self.parse_keyword(Keyword::ONLY) {
1503615035
false
15037-
} else if self.parse_keywords(&[Keyword::WITH, Keyword::TIES]) {
15038-
true
1503915036
} else {
15040-
return self.expected("one of ONLY or WITH TIES", self.peek_token());
15037+
self.parse_keywords(&[Keyword::WITH, Keyword::TIES])
1504115038
};
15039+
1504215040
Ok(Fetch {
1504315041
with_ties,
1504415042
percent,
1504515043
quantity,
1504615044
})
1504715045
}
1504815046

15049-
/// Parse a FETCH clause with Snowflake-specific syntax
15050-
fn parse_snowflake_fetch(&mut self) -> Result<Fetch, ParserError> {
15051-
// Snowflake: All additional keywords are optional. WITH TIES is not allowed.
15052-
let _ = self.parse_one_of_keywords(&[Keyword::FIRST, Keyword::NEXT]);
15053-
15054-
let quantity = Expr::Value(self.parse_value()?);
15055-
let _ = self.parse_one_of_keywords(&[Keyword::ROW, Keyword::ROWS]);
15056-
let _ = self.parse_keyword(Keyword::ONLY);
15057-
15058-
Ok(Fetch {
15059-
with_ties: false,
15060-
percent: false,
15061-
quantity: Some(quantity),
15062-
})
15063-
}
15064-
1506515047
/// Parse a FOR UPDATE/FOR SHARE clause
1506615048
pub fn parse_lock(&mut self) -> Result<LockClause, ParserError> {
1506715049
let lock_type = match self.expect_one_of_keywords(&[Keyword::UPDATE, Keyword::SHARE])? {

tests/sqlparser_snowflake.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,18 +4164,4 @@ fn test_snowflake_fetch_clause_syntax() {
41644164
"SELECT c1 FROM fetch_test FETCH FIRST 2 ROWS",
41654165
canonical,
41664166
);
4167-
4168-
snowflake()
4169-
.verified_only_select_with_canonical("SELECT c1 FROM fetch_test FETCH 2 ONLY", canonical);
4170-
let res = snowflake().parse_sql_statements("SELECT c1 FROM fetch_test FETCH 2 PERCENT");
4171-
assert_eq!(
4172-
res.unwrap_err().to_string(),
4173-
"sql parser error: Expected: end of statement, found: PERCENT"
4174-
);
4175-
let res =
4176-
snowflake().parse_sql_statements("SELECT c1 FROM fetch_test FETCH FIRST 2 ROWS WITH TIES");
4177-
assert_eq!(
4178-
res.unwrap_err().to_string(),
4179-
"sql parser error: Expected: end of statement, found: WITH"
4180-
);
41814167
}

0 commit comments

Comments
 (0)