Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,9 @@ pub trait Dialect: Debug + Any {
///
/// Example:
/// ```sql
/// SELECT t.* alias FROM t
/// SELECT t.* AS alias FROM t
/// ```
///
/// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_SELECT_list.html)
fn supports_select_wildcard_with_alias(&self) -> bool {
false
}
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ impl Dialect for PostgreSqlDialect {
true
}

fn supports_select_wildcard_with_alias(&self) -> bool {
true
}

fn supports_comma_separated_trim(&self) -> bool {
true
}
Expand Down
2 changes: 2 additions & 0 deletions src/dialect/redshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ impl Dialect for RedshiftSqlDialect {
true
}

/// Redshift supports aliasing wildcard expressions:
/// <https://docs.aws.amazon.com/redshift/latest/dg/r_SELECT_list.html>
fn supports_select_wildcard_with_alias(&self) -> bool {
true
}
Expand Down
6 changes: 1 addition & 5 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18448,11 +18448,7 @@ impl<'a> Parser<'a> {
};

let opt_alias = if self.dialect.supports_select_wildcard_with_alias() {
if self.parse_keyword(Keyword::AS) {
Some(self.parse_identifier()?)
} else {
None
}
self.maybe_parse_select_item_alias()?
} else {
None
};
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,16 +1295,29 @@ fn parse_select_wildcard_with_alias() {
dialects
.parse_sql_statements("SELECT t.* AS all_cols FROM t")
.unwrap();
dialects.one_statement_parses_to(
"SELECT t.* all_cols FROM t",
"SELECT t.* AS all_cols FROM t",
);
dialects.one_statement_parses_to(
"SELECT t.* all_cols, other_col FROM t",
"SELECT t.* AS all_cols, other_col FROM t",
);

// unqualified wildcard with alias
dialects
.parse_sql_statements("SELECT * AS all_cols FROM t")
.unwrap();
dialects.one_statement_parses_to("SELECT * all_cols FROM t", "SELECT * AS all_cols FROM t");

// mixed: regular column + qualified wildcard with alias
dialects
.parse_sql_statements("SELECT a.id, b.* AS b_cols FROM a JOIN b ON (a.id = b.a_id)")
.unwrap();
dialects.one_statement_parses_to(
"SELECT a.id, b.* b_cols FROM a JOIN b ON (a.id = b.a_id)",
"SELECT a.id, b.* AS b_cols FROM a JOIN b ON (a.id = b.a_id)",
);
}

#[test]
Expand Down
Loading