Skip to content

Commit d60e8d1

Browse files
committed
Redshift/PostgreSQL: Parse optional aliases for wildcard select items
1 parent 2b0dc2d commit d60e8d1

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/dialect/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,10 +1556,9 @@ pub trait Dialect: Debug + Any {
15561556
///
15571557
/// Example:
15581558
/// ```sql
1559+
/// SELECT t.* alias FROM t
15591560
/// SELECT t.* AS alias FROM t
15601561
/// ```
1561-
///
1562-
/// [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_SELECT_list.html)
15631562
fn supports_select_wildcard_with_alias(&self) -> bool {
15641563
false
15651564
}

src/dialect/postgresql.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ impl Dialect for PostgreSqlDialect {
307307
true
308308
}
309309

310+
fn supports_select_wildcard_with_alias(&self) -> bool {
311+
true
312+
}
313+
310314
fn supports_comma_separated_trim(&self) -> bool {
311315
true
312316
}

src/parser/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18448,11 +18448,7 @@ impl<'a> Parser<'a> {
1844818448
};
1844918449

1845018450
let opt_alias = if self.dialect.supports_select_wildcard_with_alias() {
18451-
if self.parse_keyword(Keyword::AS) {
18452-
Some(self.parse_identifier()?)
18453-
} else {
18454-
None
18455-
}
18451+
self.maybe_parse_select_item_alias()?
1845618452
} else {
1845718453
None
1845818454
};

tests/sqlparser_common.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,16 +1295,29 @@ fn parse_select_wildcard_with_alias() {
12951295
dialects
12961296
.parse_sql_statements("SELECT t.* AS all_cols FROM t")
12971297
.unwrap();
1298+
dialects.one_statement_parses_to(
1299+
"SELECT t.* all_cols FROM t",
1300+
"SELECT t.* AS all_cols FROM t",
1301+
);
1302+
dialects.one_statement_parses_to(
1303+
"SELECT t.* all_cols, other_col FROM t",
1304+
"SELECT t.* AS all_cols, other_col FROM t",
1305+
);
12981306

12991307
// unqualified wildcard with alias
13001308
dialects
13011309
.parse_sql_statements("SELECT * AS all_cols FROM t")
13021310
.unwrap();
1311+
dialects.one_statement_parses_to("SELECT * all_cols FROM t", "SELECT * AS all_cols FROM t");
13031312

13041313
// mixed: regular column + qualified wildcard with alias
13051314
dialects
13061315
.parse_sql_statements("SELECT a.id, b.* AS b_cols FROM a JOIN b ON (a.id = b.a_id)")
13071316
.unwrap();
1317+
dialects.one_statement_parses_to(
1318+
"SELECT a.id, b.* b_cols FROM a JOIN b ON (a.id = b.a_id)",
1319+
"SELECT a.id, b.* AS b_cols FROM a JOIN b ON (a.id = b.a_id)",
1320+
);
13081321
}
13091322

13101323
#[test]

0 commit comments

Comments
 (0)