File tree 6 files changed +39
-2
lines changed
6 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -350,7 +350,9 @@ impl fmt::Display for Select {
350
350
}
351
351
}
352
352
353
- write ! ( f, " {}" , display_comma_separated( & self . projection) ) ?;
353
+ if !self . projection . is_empty ( ) {
354
+ write ! ( f, " {}" , display_comma_separated( & self . projection) ) ?;
355
+ }
354
356
355
357
if let Some ( ref into) = self . into {
356
358
write ! ( f, " {into}" ) ?;
Original file line number Diff line number Diff line change @@ -127,4 +127,8 @@ impl Dialect for GenericDialect {
127
127
fn supports_struct_literal ( & self ) -> bool {
128
128
true
129
129
}
130
+
131
+ fn supports_empty_projections ( & self ) -> bool {
132
+ true
133
+ }
130
134
}
Original file line number Diff line number Diff line change @@ -410,6 +410,16 @@ pub trait Dialect: Debug + Any {
410
410
false
411
411
}
412
412
413
+ /// Return true if the dialect supports empty projections in SELECT statements
414
+ ///
415
+ /// Example
416
+ /// ```sql
417
+ /// SELECT from table_name
418
+ /// ```
419
+ fn supports_empty_projections ( & self ) -> bool {
420
+ false
421
+ }
422
+
413
423
/// Dialect-specific infix parser override
414
424
///
415
425
/// This method is called to parse the next infix expression.
Original file line number Diff line number Diff line change @@ -231,6 +231,16 @@ impl Dialect for PostgreSqlDialect {
231
231
fn supports_named_fn_args_with_expr_name ( & self ) -> bool {
232
232
true
233
233
}
234
+
235
+ /// Return true if the dialect supports empty projections in SELECT statements
236
+ ///
237
+ /// Example
238
+ /// ```sql
239
+ /// SELECT from table_name
240
+ /// ```
241
+ fn supports_empty_projections ( & self ) -> bool {
242
+ true
243
+ }
234
244
}
235
245
236
246
pub fn parse_create ( parser : & mut Parser ) -> Option < Result < Statement , ParserError > > {
Original file line number Diff line number Diff line change @@ -9692,7 +9692,12 @@ impl<'a> Parser<'a> {
9692
9692
top = Some(self.parse_top()?);
9693
9693
}
9694
9694
9695
- let projection = self.parse_projection()?;
9695
+ let projection =
9696
+ if self.dialect.supports_empty_projections() && self.peek_keyword(Keyword::FROM) {
9697
+ vec![]
9698
+ } else {
9699
+ self.parse_projection()?
9700
+ };
9696
9701
9697
9702
let into = if self.parse_keyword(Keyword::INTO) {
9698
9703
let temporary = self
Original file line number Diff line number Diff line change @@ -12576,3 +12576,9 @@ fn overflow() {
12576
12576
let statement = statements. pop ( ) . unwrap ( ) ;
12577
12577
assert_eq ! ( statement. to_string( ) , sql) ;
12578
12578
}
12579
+
12580
+ #[ test]
12581
+ fn parse_select_without_projection ( ) {
12582
+ let dialects = all_dialects_where ( |d| d. supports_empty_projections ( ) ) ;
12583
+ dialects. verified_stmt ( "SELECT FROM users" ) ;
12584
+ }
You can’t perform that action at this time.
0 commit comments