mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Handle empty projection in Postgres SELECT statements (#1613)
This commit is contained in:
parent
0647a4aa82
commit
27822e254b
6 changed files with 39 additions and 2 deletions
|
@ -350,7 +350,9 @@ impl fmt::Display for Select {
|
|||
}
|
||||
}
|
||||
|
||||
write!(f, " {}", display_comma_separated(&self.projection))?;
|
||||
if !self.projection.is_empty() {
|
||||
write!(f, " {}", display_comma_separated(&self.projection))?;
|
||||
}
|
||||
|
||||
if let Some(ref into) = self.into {
|
||||
write!(f, " {into}")?;
|
||||
|
|
|
@ -127,4 +127,8 @@ impl Dialect for GenericDialect {
|
|||
fn supports_struct_literal(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn supports_empty_projections(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -410,6 +410,16 @@ pub trait Dialect: Debug + Any {
|
|||
false
|
||||
}
|
||||
|
||||
/// Return true if the dialect supports empty projections in SELECT statements
|
||||
///
|
||||
/// Example
|
||||
/// ```sql
|
||||
/// SELECT from table_name
|
||||
/// ```
|
||||
fn supports_empty_projections(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Dialect-specific infix parser override
|
||||
///
|
||||
/// This method is called to parse the next infix expression.
|
||||
|
|
|
@ -231,6 +231,16 @@ impl Dialect for PostgreSqlDialect {
|
|||
fn supports_named_fn_args_with_expr_name(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Return true if the dialect supports empty projections in SELECT statements
|
||||
///
|
||||
/// Example
|
||||
/// ```sql
|
||||
/// SELECT from table_name
|
||||
/// ```
|
||||
fn supports_empty_projections(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_create(parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
|
||||
|
|
|
@ -9692,7 +9692,12 @@ impl<'a> Parser<'a> {
|
|||
top = Some(self.parse_top()?);
|
||||
}
|
||||
|
||||
let projection = self.parse_projection()?;
|
||||
let projection =
|
||||
if self.dialect.supports_empty_projections() && self.peek_keyword(Keyword::FROM) {
|
||||
vec![]
|
||||
} else {
|
||||
self.parse_projection()?
|
||||
};
|
||||
|
||||
let into = if self.parse_keyword(Keyword::INTO) {
|
||||
let temporary = self
|
||||
|
|
|
@ -12576,3 +12576,9 @@ fn overflow() {
|
|||
let statement = statements.pop().unwrap();
|
||||
assert_eq!(statement.to_string(), sql);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_select_without_projection() {
|
||||
let dialects = all_dialects_where(|d| d.supports_empty_projections());
|
||||
dialects.verified_stmt("SELECT FROM users");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue