Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,17 @@ impl<'a> Parser<'a> {
Token::Mul => {
return Ok(Expr::Wildcard(AttachedToken(next_token)));
}
// Handle parenthesized wildcard: (*)
Token::LParen => {
let [maybe_mul, maybe_rparen] = self.peek_tokens_ref();
if maybe_mul.token == Token::Mul && maybe_rparen.token == Token::RParen {
let mul_token = self.next_token(); // consume Mul
self.next_token(); // consume RParen
return Ok(Expr::Wildcard(AttachedToken(mul_token)));
}
// Not a (*), fall through to reset index and call parse_expr
self.prev_token();
Comment on lines +1233 to +1234
Copy link
Contributor

Choose a reason for hiding this comment

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

calling self.prev_token() doesn't seem needed? similar to the _ branch, the fall-through paths call self.index = index; to reset at the end it looks like

}
_ => (),
};

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_parenthesized_wildcard() {
// 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(_)));
}