Support HAVING without GROUP BY

...which is weird but allowed:
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#table-expression
https://dba.stackexchange.com/a/57453/15599

Also add a test for GROUP BY .. HAVING
This commit is contained in:
Nickolay Ponomarev 2019-06-17 01:04:04 +03:00
parent d60bdc0b92
commit eb3450dd51
3 changed files with 30 additions and 2 deletions

View file

@ -789,6 +789,29 @@ fn parse_select_group_by() {
);
}
#[test]
fn parse_select_having() {
let sql = "SELECT foo FROM bar GROUP BY foo HAVING COUNT(*) > 1";
let select = verified_only_select(sql);
assert_eq!(
Some(ASTNode::SQLBinaryOp {
left: Box::new(ASTNode::SQLFunction(SQLFunction {
name: SQLObjectName(vec!["COUNT".to_string()]),
args: vec![ASTNode::SQLWildcard],
over: None,
distinct: false
})),
op: SQLBinaryOperator::Gt,
right: Box::new(ASTNode::SQLValue(Value::Long(1)))
}),
select.having
);
let sql = "SELECT 'foo' HAVING 1 = 1";
let select = verified_only_select(sql);
assert!(select.having.is_some());
}
#[test]
fn parse_limit_accepts_all() {
one_statement_parses_to(