@@ -3195,6 +3195,22 @@ impl<'a> Parser<'a> {
31953195 } )
31963196 }
31973197
3198+ /// Look for all of the expected keywords in sequence, without consuming them
3199+ fn peek_keyword ( & mut self , expected : Keyword ) -> bool {
3200+ let index = self . index ;
3201+ let matched = self . parse_keyword ( expected) ;
3202+ self . index = index;
3203+ matched
3204+ }
3205+
3206+ /// Look for all of the expected keywords in sequence, without consuming them
3207+ fn peek_keywords ( & mut self , expected : & [ Keyword ] ) -> bool {
3208+ let index = self . index ;
3209+ let matched = self . parse_keywords ( expected) ;
3210+ self . index = index;
3211+ matched
3212+ }
3213+
31983214 /// Return the first non-whitespace token that has not yet been processed
31993215 /// (or None if reached end-of-file) and mark it as processed. OK to call
32003216 /// repeatedly after reaching EOF.
@@ -12311,19 +12327,6 @@ impl<'a> Parser<'a> {
1231112327 false
1231212328 }
1231312329
12314- /// Look for all of the expected keywords in sequence, without consuming them
12315- fn peek_keywords ( & mut self , expected : & [ Keyword ] ) -> bool {
12316- let index = self . index ;
12317- for kw in expected {
12318- if !self . parse_keyword ( * kw) {
12319- self . index = index;
12320- return false ;
12321- }
12322- }
12323- self . index = index;
12324- true
12325- }
12326-
1232712330 fn parse_show_stmt_options ( & mut self ) -> Result < ShowStatementOptions , ParserError > {
1232812331 let show_in;
1232912332 let mut filter_position = None ;
@@ -12354,7 +12357,8 @@ impl<'a> Parser<'a> {
1235412357 let clause = match self . parse_one_of_keywords ( & [ Keyword :: FROM , Keyword :: IN ] ) {
1235512358 Some ( Keyword :: FROM ) => ShowStatementInClause :: FROM ,
1235612359 Some ( Keyword :: IN ) => ShowStatementInClause :: IN ,
12357- _ => return Ok ( None ) ,
12360+ None => return Ok ( None ) ,
12361+ _ => return self . expected ( "FROM or IN" , self . peek_token ( ) ) ,
1235812362 } ;
1235912363
1236012364 let ( parent_type, parent_name) = match self . parse_one_of_keywords ( & [
@@ -12364,13 +12368,23 @@ impl<'a> Parser<'a> {
1236412368 Keyword :: TABLE ,
1236512369 Keyword :: VIEW ,
1236612370 ] ) {
12367- Some ( Keyword :: DATABASE ) if self . peek_keywords ( & [ Keyword :: STARTS , Keyword :: WITH ] ) => {
12371+ // If we see these next keywords it means we don't have a parent name
12372+ Some ( Keyword :: DATABASE )
12373+ if self . peek_keywords ( & [ Keyword :: STARTS , Keyword :: WITH ] )
12374+ | self . peek_keyword ( Keyword :: LIMIT ) =>
12375+ {
1236812376 ( Some ( ShowStatementInParentType :: Database ) , None )
1236912377 }
12370- Some ( Keyword :: SCHEMA ) if self . peek_keywords ( & [ Keyword :: STARTS , Keyword :: WITH ] ) => {
12378+ Some ( Keyword :: SCHEMA )
12379+ if self . peek_keywords ( & [ Keyword :: STARTS , Keyword :: WITH ] )
12380+ | self . peek_keyword ( Keyword :: LIMIT ) =>
12381+ {
1237112382 ( Some ( ShowStatementInParentType :: Schema ) , None )
1237212383 }
1237312384 Some ( parent_kw) => {
12385+ // The parent name here is still optional, for example:
12386+ // SHOW TABLES IN ACCOUNT, so parsing the object name
12387+ // may fail because the statement ends.
1237412388 let parent_name = match self . parse_object_name ( false ) {
1237512389 Ok ( n) => Some ( n) ,
1237612390 _ => None ,
@@ -12381,7 +12395,12 @@ impl<'a> Parser<'a> {
1238112395 Keyword :: SCHEMA => ( Some ( ShowStatementInParentType :: Schema ) , parent_name) ,
1238212396 Keyword :: TABLE => ( Some ( ShowStatementInParentType :: Table ) , parent_name) ,
1238312397 Keyword :: VIEW => ( Some ( ShowStatementInParentType :: View ) , parent_name) ,
12384- _ => unreachable ! ( ) ,
12398+ _ => {
12399+ return self . expected (
12400+ "one of ACCOUNT, DATABASE, SCHEMA, TABLE or VIEW" ,
12401+ self . peek_token ( ) ,
12402+ )
12403+ }
1238512404 }
1238612405 }
1238712406 None => {
0 commit comments