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
Update operations do not support joins #2796
Comments
I could try giving it a shot, but I have no idea how complicated this is going to be. @elhigu any pointers where to start? |
Not bug, but a missing feature. This has been discussed a lot during history and is one of the most wanted features in my list. I don't know if it would be hard to implement or not. I would suggest reading builder / compilation code of update operation to see if join parameters are even collected to builder for update operations. Also to start with one needs to figure out how those joins with update work with different databases (postgresql, mysql, mssql, oracledb, sqlite) and see which databases even can be supported. Pretty old issue about it #557 |
IIRC joins are only supported on update with mysql and sqlite. I've spent the last week or so working on a new API design that will make this way clearer by only allowing supported features on the builder each dialect, rather than just using the same giant base class to build the query and then having undefined runtime behavior depending on the dialect. Will open a PR with all of this once I get a little further. |
IIRC postgresql also supports kind of joins in updates, but it uses from keyword to implement them. I'm not sure how much different they are from joins. Mssql also seems to support it. For oracle there doesn't seem to be anything else but hacks for it https://stackoverflow.com/a/2446859/360060 |
This comment has been minimized.
This comment has been minimized.
May I take a stab at this? |
@JQuezada0 Yes, that would be great! You might want to take a look at how DELETE with joins was implemented: |
@JQuezada0 you can ping me here for any questions if you want. |
+1 for this, I've switched from mysql to Postgres, and this was a shock... considering that Postgres actually doing everything SQL compliant and others aren't. |
The worst part is that the query fails silently, if using Postgres it should at least throw an error. |
I think it's worth implementing a stopgap solution. Perhaps if it was possible to add some sort of validation method on update that can inspect the AST of the query before it's executed. Then rules such as banning joins on the update query can be enforced, with some suggestions on how to handle it |
Another one that is a gotcha for PostgresSQL users... this knex command will silently create an invalid query:
The need for dialect-specific checks is definitely there. |
Pull requests are very welcome. |
Which would be more ideal:
|
Could this at least throw an error or warning for now - that this isn't supported? I'm using Postgres and the error was hard to track down to this issue: |
@joelanman PR would be appreciated! |
Environment
Knex version: 0.15.2
Feature request
This is going to execute without an error, but entire join part will be ignored and all entries will be silently updated.
#1534 suggests either using raw or subquery, but neither of these solutions is particularly elegant, and API-wise there is no reason why this shouldn't work, so I would consider this a bug.
The text was updated successfully, but these errors were encountered: