Skip to content

Commit 55fc8c5

Browse files
jamiibenesch
andcommitted
Support SELECT ALL
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
1 parent 4f944dd commit 55fc8c5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/sqlparser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,11 @@ impl Parser {
13001300
/// Parse a restricted `SELECT` statement (no CTEs / `UNION` / `ORDER BY`),
13011301
/// assuming the initial `SELECT` was already consumed
13021302
pub fn parse_select(&mut self) -> Result<SQLSelect, ParserError> {
1303+
let all = self.parse_keyword("ALL");
13031304
let distinct = self.parse_keyword("DISTINCT");
1305+
if all && distinct {
1306+
return parser_err!("Cannot specify both ALL and DISTINCT in SELECT");
1307+
}
13041308
let projection = self.parse_select_list()?;
13051309

13061310
let (relation, joins) = if self.parse_keyword("FROM") {

tests/sqlparser_common.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ fn parse_select_distinct() {
135135
);
136136
}
137137

138+
#[test]
139+
fn parse_select_all() {
140+
one_statement_parses_to("SELECT ALL name FROM customer", "SELECT name FROM customer");
141+
}
142+
143+
#[test]
144+
fn parse_select_all_distinct() {
145+
let result = parse_sql_statements("SELECT ALL DISTINCT name FROM customer");
146+
assert_eq!(
147+
ParserError::ParserError("Cannot specify both ALL and DISTINCT in SELECT".to_string()),
148+
result.unwrap_err(),
149+
);
150+
}
151+
138152
#[test]
139153
fn parse_select_wildcard() {
140154
let sql = "SELECT * FROM foo";

0 commit comments

Comments
 (0)