Skip to content

Commit db23bca

Browse files
author
Alexander Beedie
committed
Support use of "BY NAME" quantifier across all set ops
1 parent be77ce5 commit db23bca

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/parser/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8138,7 +8138,7 @@ impl<'a> Parser<'a> {
81388138

81398139
pub fn parse_set_quantifier(&mut self, op: &Option<SetOperator>) -> SetQuantifier {
81408140
match op {
8141-
Some(SetOperator::Union) => {
8141+
Some(SetOperator::Except) | Some(SetOperator::Intersect | SetOperator::Union) => {
81428142
if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
81438143
SetQuantifier::DistinctByName
81448144
} else if self.parse_keywords(&[Keyword::BY, Keyword::NAME]) {
@@ -8155,15 +8155,6 @@ impl<'a> Parser<'a> {
81558155
SetQuantifier::None
81568156
}
81578157
}
8158-
Some(SetOperator::Except) | Some(SetOperator::Intersect) => {
8159-
if self.parse_keyword(Keyword::ALL) {
8160-
SetQuantifier::All
8161-
} else if self.parse_keyword(Keyword::DISTINCT) {
8162-
SetQuantifier::Distinct
8163-
} else {
8164-
SetQuantifier::None
8165-
}
8166-
}
81678158
_ => SetQuantifier::None,
81688159
}
81698160
}

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6010,6 +6010,12 @@ fn parse_union_except_intersect() {
60106010
verified_stmt("SELECT foo FROM tab UNION SELECT bar FROM TAB");
60116011
verified_stmt("(SELECT * FROM new EXCEPT SELECT * FROM old) UNION ALL (SELECT * FROM old EXCEPT SELECT * FROM new) ORDER BY 1");
60126012
verified_stmt("(SELECT * FROM new EXCEPT DISTINCT SELECT * FROM old) UNION DISTINCT (SELECT * FROM old EXCEPT DISTINCT SELECT * FROM new) ORDER BY 1");
6013+
verified_stmt("SELECT 1 AS x, 2 AS y EXCEPT BY NAME SELECT 9 AS y, 8 AS x");
6014+
verified_stmt("SELECT 1 AS x, 2 AS y EXCEPT ALL BY NAME SELECT 9 AS y, 8 AS x");
6015+
verified_stmt("SELECT 1 AS x, 2 AS y EXCEPT DISTINCT BY NAME SELECT 9 AS y, 8 AS x");
6016+
verified_stmt("SELECT 1 AS x, 2 AS y INTERSECT BY NAME SELECT 9 AS y, 8 AS x");
6017+
verified_stmt("SELECT 1 AS x, 2 AS y INTERSECT ALL BY NAME SELECT 9 AS y, 8 AS x");
6018+
verified_stmt("SELECT 1 AS x, 2 AS y INTERSECT DISTINCT BY NAME SELECT 9 AS y, 8 AS x");
60136019
}
60146020

60156021
#[test]

0 commit comments

Comments
 (0)