Skip to content

Give the destructive warning for a DELETE or UPDATE after a WITH clause - #2473

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
zzoraemon043:fix/cte-destructive-warning
Nov 25, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
zzoraemon043:fix/cte-destructive-warning

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

Description

is_destructive() looks at the first word of each statement, so a DELETE or UPDATE that starts with a common table expression runs without the destructive warning:

WITH x AS (SELECT 1) DELETE FROM t;         -- no warning, deletes every row
WITH x AS (SELECT 1) UPDATE t SET a = 1;    -- no warning, updates every row

MySQL 8.0 accepts WITH before SELECT, UPDATE and DELETE.

The new skip_with_clause() drops a leading WITH clause before the existing checks, so the main statement is checked as usual: an unrestricted DELETE/UPDATE gets the warning, and a single-table UPDATE ... WHERE stays exempt. A WHERE inside a CTE body no longer counts as the statement's own WHERE. Queries without a leading WITH are passed through unchanged.

test_is_destructive_with_clause fails on 6 of its 8 cases before the change. The full test suite has the same failures before and after the change on my Windows machine (polars, LLM, SSH and REPL tests that need extras or a POSIX shell); everything else passes.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt 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

Copy link
Copy Markdown
Contributor

So many nice PRs!

@zzoraemon043 would you like to join our developers Slack for dbcli?

@rolandwalker rolandwalker self-assigned this Nov 25, 2026
@rolandwalker
rolandwalker merged commit 37b8779 into dbcli:main Nov 25, 2026
13 checks passed
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.

2 participants