Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,15 @@ impl<'a> Parser<'a> {
Token::Mul => {
return Ok(Expr::Wildcard(AttachedToken(next_token)));
}
// Handle parenthesized wildcard: (*)
Token::LParen => {
let inner_token = self.next_token();
if inner_token.token == Token::Mul && self.peek_token().token == Token::RParen {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be simplified by calling self.peek_tokens_ref(Token::MUL, Token::RParen)?

self.next_token(); // consume RParen
return Ok(Expr::Wildcard(AttachedToken(inner_token)));
}
// Not a (*), reset and fall through to parse_expr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks incorrect per the comment, by reset should we have called prev_token() or similar to undo the consumed inner token *?

}
_ => (),
};

Expand Down
19 changes: 19 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17905,3 +17905,22 @@ fn test_parse_set_session_authorization() {
}))
);
}

#[test]
fn parse_select_distinct_parenthesized_wildcard() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn parse_select_distinct_parenthesized_wildcard() {
fn parse_select_parenthesized_wildcard() {

thinking since the syntax isn't implemented solely on the distinct keyword?

// Test SELECT DISTINCT(*) which uses a parenthesized wildcard
// The parentheses are syntactic sugar and get normalized to just *
let sql = "SELECT DISTINCT (*) FROM table1";
let canonical = "SELECT DISTINCT * FROM table1";
let select = all_dialects().verified_only_select_with_canonical(sql, canonical);
assert_eq!(select.distinct, Some(Distinct::Distinct));
assert_eq!(select.projection.len(), 1);
assert!(matches!(select.projection[0], SelectItem::Wildcard(_)));

// Also test without spaces: SELECT DISTINCT(*)
let sql_no_spaces = "SELECT DISTINCT(*) FROM table1";
let select2 = all_dialects().verified_only_select_with_canonical(sql_no_spaces, canonical);
assert_eq!(select2.distinct, Some(Distinct::Distinct));
assert_eq!(select2.projection.len(), 1);
assert!(matches!(select2.projection[0], SelectItem::Wildcard(_)));
}