-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: support UPDATE ... FROM #7841
Comments
See #7247 when fixing this issue. |
any updates on when this will be supported? |
cc @awoods187 |
@aitjcize we will not be including this in our upcoming April release. I'd love to hear more about your use case to understand your need for this feature. This will help us prioritize for future roadmap inclusion |
For our specific use case, we simply want to save as much query as possible. We are using |
I would also like to vote for this to be implemented. I need to do some conditional operations on a sum of values from child records. In PostgreSQL I can do it in a single query, while I guess in CockroachDB I will need to split it into multiple separate ones. The query looks something like this (with simplified conditions here): |
I have extended the top description of the issue to detail the work that needs to be done. It's not super simple |
top requested feature based on telemetry data |
Discussed this with @andy-kimball yesterday - Andy confirmed that once the opt framework knows about mutations, planning update...from will be a natural extension of the support for correlated subqueries and lateral joins. (Of course ensuring the statement is recognized in the first place will still require some extra work) |
Example use on the forum: https://forum.cockroachlabs.com/t/how-to-update-one-table-from-another/2217 |
https://www.postgresql.org/docs/9.5/sql-update.html Re: what happens if multiple rows match:
|
Addresses cockroachdb#7841. This change adds support for `UPDATE ... FROM` statements. The FROM clause tables are joined together with the target table and is used as input for the update. Furthermore, the RETURNING clause can reference any table in the FROM clause. TODO: - [ ] Prune the passthrough columns in the returning clause. Release note: None
Addresses cockroachdb#7841. This change adds support for `UPDATE ... FROM` statements. The FROM clause tables are joined together with the target table and is used as input for the update. Furthermore, the RETURNING clause can reference any table in the FROM clause. TODO: - [ ] Prune the passthrough columns in the returning clause. Release note: None
Addresses cockroachdb#7841. This change adds support for `UPDATE ... FROM` statements. The FROM clause tables are joined together with the target table and is used as input for the update. Furthermore, the RETURNING clause can reference any table in the FROM clause. TODO: - [ ] Prune the passthrough columns in the returning clause. Release note: None
Addresses cockroachdb#7841. This change adds support for `UPDATE ... FROM` statements. The FROM clause tables are joined together with the target table and is used as input for the update. Furthermore, the RETURNING clause can reference any table in the FROM clause. Release note: None
Addresses cockroachdb#7841. This change adds support for `UPDATE ... FROM` statements. The FROM clause tables are joined together with the target table and is used as input for the update. Furthermore, the RETURNING clause can reference any table in the FROM clause. Release note: None
39202: opt, sql: support `UPDATE ... FROM` statements r=ridwanmsharif a=ridwanmsharif Addresses #7841. This change adds support for `UPDATE ... FROM` statements. The FROM clause tables are joined together with the target table and is used as input for the update. Furthermore, the RETURNING clause can reference any table in the FROM clause. Release note: None Co-authored-by: Ridwan Sharif <[email protected]>
(edit @knz 2018-05-19)
UPDATE X SET ... = Y FROM Z
https://www.postgresql.org/docs/10/static/sql-update.html
performs (I think) a lateral join of X with Z and then makes the values computed by Z available for the scalar expressions in Y, to serve as values to update.
Full support for the feature needs support for correlated subqueries #3288 and lateral joins #24560.
Reduced support when the relational expression Z is uncorrelated (a common case) could perhaps be added with a simple join, although additional execution machinery is still needed to propagate the PK prefixes for the X operand to the join through up to the point UPDATE can pick them up.
As to which rows get updated:
The work to be done is twofold:
The text was updated successfully, but these errors were encountered: