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

Commit b9ca161

Browse files
committed
fix: support parsing parenthesized wildcard (*)
1 parent effaac5 commit b9ca161

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/parser/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,15 @@ impl<'a> Parser<'a> {
12221222
Token::Mul => {
12231223
return Ok(Expr::Wildcard(AttachedToken(next_token)));
12241224
}
1225+
// Handle parenthesized wildcard: (*)
1226+
Token::LParen => {
1227+
let inner_token = self.next_token();
1228+
if inner_token.token == Token::Mul && self.peek_token().token == Token::RParen {
1229+
self.next_token(); // consume RParen
1230+
return Ok(Expr::Wildcard(AttachedToken(inner_token)));
1231+
}
1232+
// Not a (*), reset and fall through to parse_expr
1233+
}
12251234
_ => (),
12261235
};
12271236

tests/sqlparser_common.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17905,3 +17905,22 @@ fn test_parse_set_session_authorization() {
1790517905
}))
1790617906
);
1790717907
}
17908+
17909+
#[test]
17910+
fn parse_select_distinct_parenthesized_wildcard() {
17911+
// Test SELECT DISTINCT(*) which uses a parenthesized wildcard
17912+
// The parentheses are syntactic sugar and get normalized to just *
17913+
let sql = "SELECT DISTINCT (*) FROM table1";
17914+
let canonical = "SELECT DISTINCT * FROM table1";
17915+
let select = all_dialects().verified_only_select_with_canonical(sql, canonical);
17916+
assert_eq!(select.distinct, Some(Distinct::Distinct));
17917+
assert_eq!(select.projection.len(), 1);
17918+
assert!(matches!(select.projection[0], SelectItem::Wildcard(_)));
17919+
17920+
// Also test without spaces: SELECT DISTINCT(*)
17921+
let sql_no_spaces = "SELECT DISTINCT(*) FROM table1";
17922+
let select2 = all_dialects().verified_only_select_with_canonical(sql_no_spaces, canonical);
17923+
assert_eq!(select2.distinct, Some(Distinct::Distinct));
17924+
assert_eq!(select2.projection.len(), 1);
17925+
assert!(matches!(select2.projection[0], SelectItem::Wildcard(_)));
17926+
}

0 commit comments

Comments
 (0)