Skip to content

Commit ae31568

Browse files
committed
Simplify dialect settings wrt to insert alias
1 parent db57637 commit ae31568

5 files changed

Lines changed: 17 additions & 38 deletions

File tree

src/dialect/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,14 +1238,8 @@ pub trait Dialect: Debug + Any {
12381238
false
12391239
}
12401240

1241-
/// Returns true if this dialect supports `INSERT INTO t AS alias ...`.
1242-
fn supports_insert_table_explicit_alias(&self) -> bool {
1243-
false
1244-
}
1245-
1246-
/// Returns true if this dialect supports `INSERT INTO t alias ...` with
1247-
/// `alias` _not_ preceded by the "AS" keyword.
1248-
fn supports_insert_table_implicit_alias(&self) -> bool {
1241+
/// Returns true if this dialect supports `INSERT INTO t [[AS] alias] ...`.
1242+
fn supports_insert_table_alias(&self) -> bool {
12491243
false
12501244
}
12511245

src/dialect/oracle.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ impl Dialect for OracleDialect {
111111
true
112112
}
113113

114-
/// Supports insert table aliases (but with no preceding "AS" keyword)
115-
///
116-
/// See <https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/INSERT.html#GUID-903F8043-0254-4EE9-ACC1-CB8AC0AF3423__GUID-AC239E95-0DD5-4F4B-A849-55C87840D0E6>
117-
fn supports_insert_table_implicit_alias(&self) -> bool {
114+
fn supports_insert_table_alias(&self) -> bool {
118115
true
119116
}
120117
}

src/dialect/postgresql.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,7 @@ impl Dialect for PostgreSqlDialect {
289289
true
290290
}
291291

292-
/// [Postgres] supports insert table aliases with an explicit "AS" keyword.
293-
///
294-
/// [Postgres]: https://www.postgresql.org/docs/17/sql-insert.html
295-
fn supports_insert_table_explicit_alias(&self) -> bool {
292+
fn supports_insert_table_alias(&self) -> bool {
296293
true
297294
}
298295
}

src/parser/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17166,24 +17166,24 @@ impl<'a> Parser<'a> {
1716617166
let table = self.parse_keyword(Keyword::TABLE);
1716717167
let table_object = self.parse_table_object()?;
1716817168

17169-
let table_alias = if self.dialect.supports_insert_table_implicit_alias()
17169+
let table_alias = if self.dialect.supports_insert_table_alias()
1717017170
&& !self.peek_sub_query()
1717117171
&& self
17172-
.peek_one_of_keywords(&[Keyword::AS, Keyword::DEFAULT, Keyword::VALUES])
17172+
.peek_one_of_keywords(&[Keyword::DEFAULT, Keyword::VALUES])
1717317173
.is_none()
1717417174
{
17175-
self.maybe_parse(|parser| parser.parse_identifier())?
17176-
.map(|alias| TableAliasWithoutColumns {
17177-
explicit: false,
17178-
alias,
17175+
if self.parse_keyword(Keyword::AS) {
17176+
Some(TableAliasWithoutColumns {
17177+
explicit: true,
17178+
alias: self.parse_identifier()?,
1717917179
})
17180-
} else if self.dialect.supports_insert_table_explicit_alias()
17181-
&& self.parse_keyword(Keyword::AS)
17182-
{
17183-
Some(TableAliasWithoutColumns {
17184-
explicit: true,
17185-
alias: self.parse_identifier()?,
17186-
})
17180+
} else {
17181+
self.maybe_parse(|parser| parser.parse_identifier())?
17182+
.map(|alias| TableAliasWithoutColumns {
17183+
explicit: false,
17184+
alias,
17185+
})
17186+
}
1718717187
} else {
1718817188
None
1718917189
};

tests/sqlparser_oracle.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,6 @@ fn test_insert_without_alias() {
483483
))
484484
);
485485

486-
// check AS
487-
let sql = "INSERT INTO AS t default SELECT 'a' FROM dual";
488-
assert_eq!(
489-
oracle_dialect.parse_sql_statements(sql),
490-
Err(ParserError::ParserError(
491-
"Expected: SELECT, VALUES, or a subquery in the query body, found: default".into()
492-
))
493-
);
494-
495486
// check SELECT
496487
let sql = "INSERT INTO t SELECT 'a' FROM dual";
497488
let stmt = oracle_dialect.verified_stmt(sql);

0 commit comments

Comments
 (0)