Skip to content

Conversation

@rolandwalker
Copy link
Contributor

Description

Only suppress the destructive-command warning for the simple case of a single-table UPDATE with a WHERE clause.

Fixes #791.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Feb 7, 2026
Copy link
Contributor

@scottnemes scottnemes left a comment

Choose a reason for hiding this comment

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

This works in the case of always warning if you run a multi table update, regardless of where clause.

However it diverges from the behavior of a single table update, where if you do have a where clause on a single table update, it will not warn. However with this change, every multi table update will warn, even if you have a full where clause. This goes back to the comment I posted in the issue originally, where it is more difficult to make sure a multi table where clause covers all tables due to the possible variations on specifying columns in the where clause (with or without a table prefix, and aliases). I.e. if you are updating t1 and t2, you need a where clause with columns from both t1 and t2.

So long and short, this will start forcing a warn on all multi table updates, even if they have a full where clause. Users can disable warns on update at that point, but then they end up worse than before.

Before:

update t1, t2 set t1.id = 3, t2.id = 3; # warning, no where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1; # no warning, partial where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1 and t2.id = 1; # no warning, full where clause

After

update t1, t2 set t1.id = 3, t2.id = 3; # warning, no where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1; # warning, partial where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1 and t2.id = 1; # warning, full where clause

So in the case where someone runs a multi table update without a full where clause, this change is better as that is dangerous. However if someone runs a multi table update with a full where clause, it still warns, which might not be ideal.

@rolandwalker
Copy link
Contributor Author

So long and short, this will start forcing a warn on all multi table updates, even if they have a full where clause.

That was the intention of the PR! We'd have to go deep into the SQL to do otherwise. Open to that, too!

Only suppress the destructive-command warning for the simple case of a
single-table UPDATE with a WHERE clause.
@rolandwalker rolandwalker force-pushed the RW/warn-on-multi-table-updates branch from 1e97caf to fd9ca86 Compare February 7, 2026 19:29
@scottnemes
Copy link
Contributor

So long and short, this will start forcing a warn on all multi table updates, even if they have a full where clause.

That was the intention of the PR! We'd have to go deep into the SQL to do otherwise. Open to that, too!

Yeah I'm pointing out this makes divergent behavior, which in the past you've always been against. But if it's working as you want, then that's okay; it works as described.

@rolandwalker
Copy link
Contributor Author

Agreed, @scottnemes, this is a super tricky feature. Even with the prior and current implementations, nothing helps you if you type WHERE 1 = 1. It probably would have been better all along to treat UPDATE the same as other keywords.

@rolandwalker rolandwalker merged commit 3cfcb28 into main Feb 9, 2026
8 checks passed
@rolandwalker rolandwalker deleted the RW/warn-on-multi-table-updates branch February 9, 2026 08:21
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.

Mark dangerous multiple-table updates as destructive queries

2 participants