-
Notifications
You must be signed in to change notification settings - Fork 764
Databricks: support INSERT BY NAME #2403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
68ff95d
3aa09e6
353ba80
2447117
123a295
dcc620f
ed1d6b4
6336ef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6093,6 +6093,7 @@ fn test_simple_postgres_insert_with_alias() { | |
| span: Span::empty(), | ||
| }) | ||
| ], | ||
| by_name: false, | ||
| overwrite: false, | ||
| source: Some(Box::new(Query { | ||
| with: None, | ||
|
|
@@ -6173,6 +6174,7 @@ fn test_simple_postgres_insert_with_alias() { | |
| span: Span::empty(), | ||
| }) | ||
| ], | ||
| by_name: false, | ||
| overwrite: false, | ||
| source: Some(Box::new(Query { | ||
| with: None, | ||
|
|
@@ -6255,6 +6257,7 @@ fn test_simple_insert_with_quoted_alias() { | |
| span: Span::empty(), | ||
| }) | ||
| ], | ||
| by_name: false, | ||
| overwrite: false, | ||
| source: Some(Box::new(Query { | ||
| with: None, | ||
|
|
@@ -9663,3 +9666,22 @@ fn parse_right_deep_join_chain() { | |
| // NATURAL JOIN followed by a constrained join must stay left-associative. | ||
| pg().verified_stmt("SELECT * FROM t0 NATURAL JOIN t1 INNER JOIN t2 ON true"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_insert_by_name_keywords_as_table_and_alias() { | ||
| // Without a table name, `BY NAME` is not an INSERT BY NAME clause. PostgreSQL | ||
| // treats `BY` as the table name and `NAME` as its implicit table alias. | ||
| match pg().verified_stmt("INSERT INTO BY NAME SELECT 1 AS a") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this test case specific to postgres? I would imagine that its part of the parse_insert_by_name test in common and that all dialects have the same behavior? (i.e. a table_name is required in order for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@iffyio I agree that the requirement for table_name is dialect-agnostic. However, the fallback parse is not identical across all dialects in sqlparser: BY is parsed as the table name and NAME as an implicit alias only for dialects that support INSERT table aliases, currently PostgreSQL and Oracle. I think I can move the test into the common parse_insert_by_name coverage and restrict it to those dialects. |
||
| Statement::Insert(Insert { | ||
| table: TableObject::TableName(table), | ||
| table_alias: Some(table_alias), | ||
| by_name, | ||
| .. | ||
| }) => { | ||
| assert_eq!(table.to_string(), "BY"); | ||
| assert_eq!(table_alias.alias.value, "NAME"); | ||
| assert!(!by_name); | ||
| } | ||
| statement => panic!("Expected INSERT statement, got: {statement:?}"), | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.