Databricks: support INSERT BY NAME - #2403
Conversation
| by_name = columns.is_empty() | ||
| && self.dialect.supports_insert_by_name() |
There was a problem hiding this comment.
| by_name = columns.is_empty() | |
| && self.dialect.supports_insert_by_name() | |
| by_name = by_name.is_none() | |
| && self.dialect.supports_insert_by_name() |
I think we can drop the columns check? its not clear why it would be needed at this layer, if the implication is something semantic then that can be left up to the consumer to validate. Relatedly, I assume we need to only set the name if we don't already have one (can we cover that scenario in the tests)?
|
Hi @iffyio , I have committed some changes as per your suggestions. Could you plz take a look again? |
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
Cover BY NAME alongside a PARTITION clause and a table alias to guard against conflicts with neighbouring INSERT syntax, and rely on verified_stmt in the Databricks tests since the AST is asserted in the common tests. Co-authored-by: Cursor <cursoragent@cursor.com>
| 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") { |
There was a problem hiding this comment.
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 BY NAME to be accepted as a clause so the grammar seems dialect agnostic from what I can tell from the databricks docs)
There was a problem hiding this comment.
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
BY NAMEto be accepted as a clause so the grammar seems dialect agnostic from what I can tell from the databricks docs)
@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.
Summary
This PR adds support for Databricks INSERT ... BY NAME syntax.
Examples
Testing
cargo test --test sqlparser_databricks test_databricks_insert_by_name
Relevant PostgreSQL INSERT regression tests