Skip to content

feat: support "replace using" for insert DML - #7950

Merged
geooo109 merged 9 commits into
tobymao:mainfrom
nlpersimon:feat/replace-using
Aug 3, 2026
Merged

feat: support "replace using" for insert DML#7950
geooo109 merged 9 commits into
tobymao:mainfrom
nlpersimon:feat/replace-using

Conversation

@nlpersimon

@nlpersimon nlpersimon commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

To fix #7949

@geooo109 geooo109 self-assigned this Jul 27, 2026

@geooo109 geooo109 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add support for:

REPLACE ON boolean_expression

Comment thread tests/dialects/test_databricks.py Outdated
Comment thread sqlglot/parser.py Outdated
@geooo109

Copy link
Copy Markdown
Collaborator

@nlpersimon any plans to finish this?

@nlpersimon

Copy link
Copy Markdown
Contributor Author

@nlpersimon any plans to finish this?

yes. appreciate your comment!
I will implement the support for "replace on" and address the other comments you left by this week.

@georgesittas

Copy link
Copy Markdown
Collaborator

closing this for now, feel free to reopen when ready.

@nlpersimon

Copy link
Copy Markdown
Contributor Author

Hi @georgesittas @geooo109 , I am ready, could you reopen this PR? Or should I open a new PR?

@georgesittas georgesittas reopened this Aug 2, 2026
@georgesittas

Copy link
Copy Markdown
Collaborator

@nlpersimon go for it

@nlpersimon

Copy link
Copy Markdown
Contributor Author

@geooo109 I implemented the support for "replace on" in 1480c2c . I thought it was a trivial work that I can just implement it as

 elif self._match(TokenType.ON):
     replace_on = self._parse_disjunction()
     if replace_on is None:
         self.raise_error("Expected a condition after REPLACE ON")

but this implementation cannot handle the following query

INSERT INTO TABLE students AS t
  REPLACE ON t.name <=> s.name
  (SELECT * FROM people) AS s

because the parser regards s.name (SELECT * FROM people) as an anonymous function.

The solution I came up with is implementing a method _parse_with_token_barrier to restrict the visibility of the parser so that the parser can parse disjunction of the "replace on" clause without misinterpreting the source subquery as an anonymous function.

@geooo109

geooo109 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

@nlpersimon thanks for trying to solve the ON case. This problem is more complex than it seemed. Let's revert the solution for the ON and support the rest. I will do a follow up in the future to resolve this.

@nlpersimon

Copy link
Copy Markdown
Contributor Author

@nlpersimon thanks for trying to solve the ON case. This problem is more complex than it seemed. Let's revert the solution for the ON and support the rest. I will do a follow up in the future to resolve this.

reverted. thank you!

@geooo109
geooo109 merged commit 8a79d07 into tobymao:main Aug 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support REPLACE USING for INSERT

3 participants