MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_query_body

Method parse_query_body

src/sql-parser/src/parser.rs:7733–7758  ·  view source on GitHub ↗

Parse a "query body", which is an expression with roughly the following grammar: ```text query_body ::= restricted_select | '(' subquery ')' | set_operation restricted_select ::= 'SELECT' [expr_list] [ from ] [ where ] [ groupby_having ] subquery ::= query_body [ order_by_limit ] set_operation ::= query_body { 'UNION' | 'EXCEPT' | 'INTERSECT' } [ 'ALL' ] query_body ```

(&mut self, precedence: SetPrecedence)

Source from the content-addressed store, hash-verified

7731 /// set_operation ::= query_body { 'UNION' | 'EXCEPT' | 'INTERSECT' } [ 'ALL' ] query_body
7732 /// ```
7733 fn parse_query_body(&mut self, precedence: SetPrecedence) -> Result<SetExpr<Raw>, ParserError> {
7734 // We parse the expression using a Pratt parser, as in `parse_expr()`.
7735 // Start by parsing a restricted SELECT or a `(subquery)`:
7736 let expr = if self.parse_keyword(SELECT) {
7737 SetExpr::Select(Box::new(self.parse_select()?))
7738 } else if self.consume_token(&Token::LParen) {
7739 // CTEs are not allowed here, but the parser currently accepts them
7740 let subquery = self.parse_query()?;
7741 self.expect_token(&Token::RParen)?;
7742 SetExpr::Query(Box::new(subquery))
7743 } else if self.parse_keyword(VALUES) {
7744 SetExpr::Values(self.parse_values()?)
7745 } else if self.parse_keyword(SHOW) {
7746 SetExpr::Show(self.parse_show()?)
7747 } else if self.parse_keyword(TABLE) {
7748 SetExpr::Table(self.parse_raw_name()?)
7749 } else {
7750 return self.expected(
7751 self.peek_pos(),
7752 "SELECT, VALUES, or a subquery in the query body",
7753 self.peek_token(),
7754 );
7755 };
7756
7757 self.parse_query_body_seeded(precedence, expr)
7758 }
7759
7760 fn parse_query_body_seeded(
7761 &mut self,

Callers 2

parse_queryMethod · 0.80

Calls 15

SelectClass · 0.85
parse_keywordMethod · 0.80
parse_selectMethod · 0.80
consume_tokenMethod · 0.80
expect_tokenMethod · 0.80
parse_valuesMethod · 0.80
parse_showMethod · 0.80
parse_raw_nameMethod · 0.80
expectedMethod · 0.80
peek_posMethod · 0.80
peek_tokenMethod · 0.80

Tested by

no test coverage detected