feat: support UPDATE ... FROM ... syntax#833
Conversation
|
Just tagging @tyt2y3 @billy1624 (as the most active/recent mergers) to try and get some traction on this 😅 |
|
Thank you for the PR! sadly |
Totally valid. We can restrict it by feature flag, if that works? So it's only available when the proper feature flags are enabled, and the emitted queries are syntactically correct for the enabled feature-set. Out of curiosity, do you happen to know the equivalent syntax for MySQL? Once-upon-a-time I was extremely familiar with the major flavors of SQL syntax, as I was doing a lot of tinkering in the internals of SQLAlchemy due to being the maintainer for a couple of esoteric dialects for that package. In the intervening time, I've transitioned to rust almost completely, so tl;dr SeaORM/SeaQuery are the gotos AFAIC 😅 Anyway, if you're amenable to the update, I'll sort out the syntax / engine pairings and update the PR. |
src/query/update.rs
Outdated
| /// | ||
| /// assert_eq!( | ||
| /// query.to_string(MysqlQueryBuilder), | ||
| /// "UPDATE `glyph` SET `tokens` = `character`.`character` FROM `character` WHERE `glyph`.`image` = `character`.`user_data`" |
There was a problem hiding this comment.
The syntax of MySQL appears similar, but not identical. Here a MySQL UPDATE JOIN could be used to achieve the same:
UPDATE `glyph`
JOIN `character`
ON `glyph`.`image` = `character`.`user_data`
SET `glyph`.`tokens` = `character`.`character`;There was a problem hiding this comment.
@gronke Took a wild swing at at least getting started here, and extracted the specific behavior into a discrete method (prepare_update_from_table_refs) so it can be overridden as needed by whichever dialect. I've got the MySQL-specific handling as a unimplemented! call at the moment though, cause I've got a case of end-of-year-holidays-brain.
If you have a second, would you take a look at the changes and let me know if there's a better / more preferable way of doing this please let me know? Otherwise I'll carry on as time allows 😁
…r `UPDATE ... FROM ...` behavior
6533421 to
f787e93
Compare
|
Would love to see this landed! This would provide support for stuff like using SeaQuery to construct queries for batch update operations that utilize CTEs and value tuples. |
I'd love to get it landed 😅. I see you've got a |
|
I will give it a try |
PR Info
New Features
FROMclause in anUPDATEqueryUPDATE table1 SET some_column = table2.another_column FROM table2 WHERE table1.another_column = table2.a_different_column