WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
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
9 changes: 9 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,15 @@ 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)));
}
}
_ => (),
};

Expand Down
19 changes: 19 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17953,3 +17953,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(_)));
}