Skip to content

Commit 86a2fbd

Browse files
authored
Merge pull request #76 from benesch/select-all
Support SELECT ALL
2 parents 7a6a66b + 55fc8c5 commit 86a2fbd

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
@@ -1354,7 +1354,11 @@ impl Parser {
13541354
/// Parse a restricted `SELECT` statement (no CTEs / `UNION` / `ORDER BY`),
13551355
/// assuming the initial `SELECT` was already consumed
13561356
pub fn parse_select(&mut self) -> Result<SQLSelect, ParserError> {
1357+
let all = self.parse_keyword("ALL");
13571358
let distinct = self.parse_keyword("DISTINCT");
1359+
if all && distinct {
1360+
return parser_err!("Cannot specify both ALL and DISTINCT in SELECT");
1361+
}
13581362
let projection = self.parse_select_list()?;
13591363

13601364
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)