Skip to content

Commit d9e5bd7

Browse files
committed
Simplify dialect settings wrt to insert alias
1 parent a840cd6 commit d9e5bd7

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
@@ -1240,14 +1240,8 @@ pub trait Dialect: Debug + Any {
12401240
false
12411241
}
12421242

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

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
@@ -17229,24 +17229,24 @@ impl<'a> Parser<'a> {
1722917229
let table = self.parse_keyword(Keyword::TABLE);
1723017230
let table_object = self.parse_table_object()?;
1723117231

17232-
let table_alias = if self.dialect.supports_insert_table_implicit_alias()
17232+
let table_alias = if self.dialect.supports_insert_table_alias()
1723317233
&& !self.peek_sub_query()
1723417234
&& self
17235-
.peek_one_of_keywords(&[Keyword::AS, Keyword::DEFAULT, Keyword::VALUES])
17235+
.peek_one_of_keywords(&[Keyword::DEFAULT, Keyword::VALUES])
1723617236
.is_none()
1723717237
{
17238-
self.maybe_parse(|parser| parser.parse_identifier())?
17239-
.map(|alias| TableAliasWithoutColumns {
17240-
explicit: false,
17241-
alias,
17238+
if self.parse_keyword(Keyword::AS) {
17239+
Some(TableAliasWithoutColumns {
17240+
explicit: true,
17241+
alias: self.parse_identifier()?,
1724217242
})
17243-
} else if self.dialect.supports_insert_table_explicit_alias()
17244-
&& self.parse_keyword(Keyword::AS)
17245-
{
17246-
Some(TableAliasWithoutColumns {
17247-
explicit: true,
17248-
alias: self.parse_identifier()?,
17249-
})
17243+
} else {
17244+
self.maybe_parse(|parser| parser.parse_identifier())?
17245+
.map(|alias| TableAliasWithoutColumns {
17246+
explicit: false,
17247+
alias,
17248+
})
17249+
}
1725017250
} else {
1725117251
None
1725217252
};

tests/sqlparser_oracle.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,6 @@ fn test_insert_without_alias() {
490490
))
491491
);
492492

493-
// check AS
494-
let sql = "INSERT INTO AS t default SELECT 'a' FROM dual";
495-
assert_eq!(
496-
oracle_dialect.parse_sql_statements(sql),
497-
Err(ParserError::ParserError(
498-
"Expected: SELECT, VALUES, or a subquery in the query body, found: default".into()
499-
))
500-
);
501-
502493
// check SELECT
503494
let sql = "INSERT INTO t SELECT 'a' FROM dual";
504495
let stmt = oracle_dialect.verified_stmt(sql);

0 commit comments

Comments
 (0)