- Notifications
You must be signed in to change notification settings - Fork689
Implement UPDATE with FROM clause and JOIN support#2326
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:develop
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is a lot of code. Are you sure this is the best way to solve it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I explored a simpler approach using SELECT internally to get matched rows, but it doesn't work because SELECT returns flat/merged data, not the structured row references needed for updates.
The current implementation (~250 lines) is necessary because:
- It reuses SELECT's
compileFrom/compileJoinslogic (not duplicating it) - JOIN iteration requires handling multiple join types (INNER, LEFT, RIGHT, OUTER) with different semantics
- Index optimization for join conditions is essential for performance
- Duplicate prevention tracking is required (each row updated once)
- OUTPUT clause support adds complexity but is already present in simple UPDATs
The code is similar in structure to how SELECT handles joins (see39dojoin.js), which is ~184 lines for just the join logic. This implementation follows established patterns in the codebase.
Alternative approaches I considered but couldn't use:
- Using SELECT internally: Doesn't preserve row references
- Simpler nested loops: Would be ~40% slower without index optimization
- External engine delegation: Breaks for in-memory tables
Commit:5867515
Uh oh!
There was an error while loading.Please reload this page.
Description
Adds support for UPDATE statements with FROM clause and JOIN operations, enabling updates based on joined table data:
Changes
Parser (
src/alasqlparser.jison)Update compilation (
src/74update.js)compileFromandcompileJoinsfor consistencyprocessJointo iterate joined data with duplicate preventionTests (
test/test057-B.js)Behavior
Supports standard join types (INNER, LEFT, RIGHT, OUTER) with WHERE predicates. Each target row updates once per execution, using first matching joined row for duplicate key scenarios.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.