File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,10 +95,6 @@ impl Dialect for DatabricksDialect {
9595 true
9696 }
9797
98- fn supports_insert_by_name ( & self ) -> bool {
99- true
100- }
101-
10298 /// See <https://docs.databricks.com/aws/en/sql/language-manual/functions/bangsign>
10399 fn supports_bang_not_operator ( & self ) -> bool {
104100 true
Original file line number Diff line number Diff line change @@ -320,8 +320,4 @@ impl Dialect for GenericDialect {
320320 fn supports_aliased_function_args ( & self ) -> bool {
321321 true
322322 }
323-
324- fn supports_insert_by_name ( & self ) -> bool {
325- true
326- }
327323}
Original file line number Diff line number Diff line change @@ -1353,13 +1353,6 @@ pub trait Dialect: Debug + Any {
13531353 false
13541354 }
13551355
1356- /// Returns true if this dialect supports `INSERT INTO ... BY NAME ...`.
1357- ///
1358- /// Databricks: <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-dml-insert-into>
1359- fn supports_insert_by_name ( & self ) -> bool {
1360- false
1361- }
1362-
13631356 /// Returns true if this dialect supports `SET` statements without an explicit
13641357 /// assignment operator such as `=`. For example: `SET SHOWPLAN_XML ON`.
13651358 fn supports_set_stmt_without_operator ( & self ) -> bool {
Original file line number Diff line number Diff line change @@ -18314,7 +18314,9 @@ impl<'a> Parser<'a> {
1831418314 let table = self.parse_keyword(Keyword::TABLE);
1831518315 let table_object = self.parse_table_object()?;
1831618316
18317+ // `BY NAME` is an INSERT clause, not a table alias.
1831718318 let table_alias = if self.dialect.supports_insert_table_alias()
18319+ && !self.peek_keywords(&[Keyword::BY, Keyword::NAME])
1831818320 && !self.peek_sub_query()
1831918321 && self
1832018322 .peek_one_of_keywords(&[Keyword::DEFAULT, Keyword::VALUES])
@@ -18349,9 +18351,7 @@ impl<'a> Parser<'a> {
1834918351 self.parse_parenthesized_qualified_column_list(Optional, is_mysql)?;
1835018352
1835118353 let partitioned = self.parse_insert_partition()?;
18352- by_name = columns.is_empty()
18353- && self.dialect.supports_insert_by_name()
18354- && self.parse_keywords(&[Keyword::BY, Keyword::NAME]);
18354+ by_name = self.parse_keywords(&[Keyword::BY, Keyword::NAME]);
1835518355 // Hive allows you to specify columns after partitions as well if you want.
1835618356 let after_columns = if dialect_of!(self is HiveDialect) {
1835718357 self.parse_parenthesized_column_list(Optional, false)?
Original file line number Diff line number Diff line change @@ -19584,3 +19584,18 @@ fn parse_function_arg_call_chain_no_exponential_blowup() {
1958419584 rx.recv_timeout(Duration::from_secs(5))
1958519585 .expect("parser should reject this quickly, not loop exponentially");
1958619586}
19587+
19588+ #[test]
19589+ fn parse_insert_by_name_in_all_dialects() {
19590+ verified_stmt("INSERT INTO target BY NAME SELECT 1 AS a");
19591+
19592+ match verified_stmt("INSERT INTO target (a) BY NAME SELECT 1 AS a") {
19593+ Statement::Insert(Insert {
19594+ by_name, columns, ..
19595+ }) => {
19596+ assert!(by_name);
19597+ assert_eq!(columns.len(), 1);
19598+ }
19599+ _ => unreachable!(),
19600+ }
19601+ }
You can’t perform that action at this time.
0 commit comments