mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-05 05:30:32 +00:00
Allow to use ()
as the GROUP BY nothing (#1347)
This commit is contained in:
parent
48ea5640a2
commit
b27abf00e2
2 changed files with 33 additions and 0 deletions
|
@ -1487,6 +1487,11 @@ impl<'a> Parser<'a> {
|
|||
let result = self.parse_comma_separated(|p| p.parse_tuple(true, true))?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Ok(Expr::Rollup(result))
|
||||
} else if self.consume_tokens(&[Token::LParen, Token::RParen]) {
|
||||
// PostgreSQL allow to use empty tuple as a group by expression,
|
||||
// e.g. `GROUP BY (), name`. Please refer to GROUP BY Clause section in
|
||||
// [PostgreSQL](https://www.postgresql.org/docs/16/sql-select.html)
|
||||
Ok(Expr::Tuple(vec![]))
|
||||
} else {
|
||||
self.parse_expr()
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ mod test_utils;
|
|||
|
||||
#[cfg(test)]
|
||||
use pretty_assertions::assert_eq;
|
||||
use sqlparser::ast::Expr::Identifier;
|
||||
use sqlparser::test_utils::all_dialects_except;
|
||||
|
||||
#[test]
|
||||
|
@ -10278,3 +10279,30 @@ fn parse_auto_increment_too_large() {
|
|||
|
||||
assert!(res.is_err(), "{res:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_group_by_nothing() {
|
||||
let Select { group_by, .. } = all_dialects_where(|d| d.supports_group_by_expr())
|
||||
.verified_only_select("SELECT count(1) FROM t GROUP BY ()");
|
||||
{
|
||||
std::assert_eq!(
|
||||
GroupByExpr::Expressions(vec![Expr::Tuple(vec![])], vec![]),
|
||||
group_by
|
||||
);
|
||||
}
|
||||
|
||||
let Select { group_by, .. } = all_dialects_where(|d| d.supports_group_by_expr())
|
||||
.verified_only_select("SELECT name, count(1) FROM t GROUP BY name, ()");
|
||||
{
|
||||
std::assert_eq!(
|
||||
GroupByExpr::Expressions(
|
||||
vec![
|
||||
Identifier(Ident::new("name".to_string())),
|
||||
Expr::Tuple(vec![])
|
||||
],
|
||||
vec![]
|
||||
),
|
||||
group_by
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue