File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ impl ToString for SQLSetOperator {
96
96
/// to a set operation like `UNION`.
97
97
#[ derive( Debug , Clone , PartialEq ) ]
98
98
pub struct SQLSelect {
99
+ pub all : bool ,
99
100
pub distinct : bool ,
100
101
/// projection expressions
101
102
pub projection : Vec < SQLSelectItem > ,
@@ -114,7 +115,8 @@ pub struct SQLSelect {
114
115
impl ToString for SQLSelect {
115
116
fn to_string ( & self ) -> String {
116
117
let mut s = format ! (
117
- "SELECT{} {}" ,
118
+ "SELECT{}{} {}" ,
119
+ if self . all { " ALL" } else { "" } ,
118
120
if self . distinct { " DISTINCT" } else { "" } ,
119
121
comma_separated_string( & self . projection)
120
122
) ;
Original file line number Diff line number Diff line change @@ -1383,7 +1383,11 @@ impl Parser {
1383
1383
/// Parse a restricted `SELECT` statement (no CTEs / `UNION` / `ORDER BY`),
1384
1384
/// assuming the initial `SELECT` was already consumed
1385
1385
pub fn parse_select ( & mut self ) -> Result < SQLSelect , ParserError > {
1386
+ let all = self . parse_keyword ( "ALL" ) ;
1386
1387
let distinct = self . parse_keyword ( "DISTINCT" ) ;
1388
+ if all && distinct {
1389
+ return parser_err ! ( "Cannot specify both ALL and DISTINCT in SELECT" ) ;
1390
+ }
1387
1391
let projection = self . parse_select_list ( ) ?;
1388
1392
1389
1393
let ( relation, joins) = if self . parse_keyword ( "FROM" ) {
@@ -1413,6 +1417,7 @@ impl Parser {
1413
1417
} ;
1414
1418
1415
1419
Ok ( SQLSelect {
1420
+ all,
1416
1421
distinct,
1417
1422
projection,
1418
1423
selection,
Original file line number Diff line number Diff line change @@ -135,6 +135,26 @@ fn parse_select_distinct() {
135
135
) ;
136
136
}
137
137
138
+ #[ test]
139
+ fn parse_select_all ( ) {
140
+ let sql = "SELECT ALL name FROM customer" ;
141
+ let select = verified_only_select ( sql) ;
142
+ assert_eq ! ( false , select. distinct) ;
143
+ assert_eq ! (
144
+ & SQLSelectItem :: UnnamedExpression ( ASTNode :: SQLIdentifier ( "name" . to_string( ) ) ) ,
145
+ only( & select. projection)
146
+ ) ;
147
+ }
148
+
149
+ #[ test]
150
+ fn parse_select_all_distinct ( ) {
151
+ let result = parse_sql_statements ( "SELECT ALL DISTINCT name FROM customer" ) ;
152
+ assert_eq ! (
153
+ ParserError :: ParserError ( "Cannot specify both ALL and DISTINCT in SELECT" . to_string( ) ) ,
154
+ result. unwrap_err( ) ,
155
+ ) ;
156
+ }
157
+
138
158
#[ test]
139
159
fn parse_select_wildcard ( ) {
140
160
let sql = "SELECT * FROM foo" ;
You can’t perform that action at this time.
0 commit comments