missing-where¶
Default severity: warn
What it does¶
Reports an UPDATE or DELETE with no WHERE, on its keyword: inside a CTE too, and
with UPDATE ... FROM or DELETE ... USING.
from sqlty import SQL
# error: [missing-where] "`DELETE` without `WHERE` removes every row of `users`: add a `WHERE`, or `WHERE true` to mean it"
q = SQL[tuple[()]]("--sql\nDELETE FROM users")
Open in playgroundAny WHERE says the filter is meant, WHERE true included:
from sqlty import SQL
# error:
q = SQL[tuple[()]]("--sql\nUPDATE users SET name = 'x' WHERE true")
Open in playgroundWhy is this bad?¶
A forgotten WHERE rewrites or empties the whole table, and the database runs it
without a complaint.
How to fix¶
Add the WHERE the statement was meant to have, or WHERE true when it is meant to
touch every row.
Configuration¶
A warning by default: the statement is valid SQL. Turn it into an error or off:
[tool.sqlty.rules]
missing-where = "error"
Needs no schema. A MySQL UPDATE or DELETE with LIMIT is not reported, and
migrations are not checked.