Support SELECT ALL

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
This commit is contained in:
Jamie Brandon 2019-05-22 14:09:18 +01:00 committed by Nikhil Benesch
parent 4f944dd4aa
commit 55fc8c5a57
No known key found for this signature in database
GPG key ID: F7386C5DEADABA7F
2 changed files with 18 additions and 0 deletions

View file

@ -1300,7 +1300,11 @@ impl Parser {
/// Parse a restricted `SELECT` statement (no CTEs / `UNION` / `ORDER BY`),
/// assuming the initial `SELECT` was already consumed
pub fn parse_select(&mut self) -> Result<SQLSelect, ParserError> {
let all = self.parse_keyword("ALL");
let distinct = self.parse_keyword("DISTINCT");
if all && distinct {
return parser_err!("Cannot specify both ALL and DISTINCT in SELECT");
}
let projection = self.parse_select_list()?;
let (relation, joins) = if self.parse_keyword("FROM") {

View file

@ -135,6 +135,20 @@ fn parse_select_distinct() {
);
}
#[test]
fn parse_select_all() {
one_statement_parses_to("SELECT ALL name FROM customer", "SELECT name FROM customer");
}
#[test]
fn parse_select_all_distinct() {
let result = parse_sql_statements("SELECT ALL DISTINCT name FROM customer");
assert_eq!(
ParserError::ParserError("Cannot specify both ALL and DISTINCT in SELECT".to_string()),
result.unwrap_err(),
);
}
#[test]
fn parse_select_wildcard() {
let sql = "SELECT * FROM foo";