Repository navigation
feat(rules): report queries that cannot do what they appear to - #15
Merged
Merged
Conversation
Add eight report-only Rules on the parsed statements and tokens: duplicate CTE names (SQC046), CASE WHEN NULL and IN (NULL) (SQC047), literal-zero division (SQC048), unfiltered UPDATE or DELETE (SQC049, opt-in), INSERT without a column list (SQC050, opt-in), NATURAL JOIN (SQC051), reversed literal BETWEEN bounds (SQC052) and aggregates or windows in WHERE, ON or GROUP BY (SQC053).
Deploying sqlclean with
|
| Latest commit: |
c3d2c65
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2b24ed50.sqlclean.pages.dev |
| Branch Preview URL: | https://feat-safety-rules.sqlclean.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The safety review found mistakes SQLClean misses even with every Rule selected: duplicate CTE names,
WHEN NULL, literal-zero division, reversedBETWEEN, aggregates inWHERE,NATURAL JOIN, and unguarded writes.Changes
Eight report-only Rules in
sql_quality/_helpers/safety.rs. The AST decides statement and CTE facts and which names are aggregates; tokens locate findings exactly.SQC046duplicate CTE names (dialect-aware quoting and case, perWITHscope),SQC047CASE x WHEN NULLand singletonIN (NULL),SQC048/,%,//,MODby a literal zero,SQC051NATURAL JOIN,SQC052reversed number or ISO dateBETWEENbounds (NOTreported,SYMMETRICskipped),SQC053aggregates or windows inWHERE,ON,GROUP BY.SQC049UPDATE/DELETEwith no row-reading predicate, join condition orLIMIT(WHERE TRUEcounts as none),SQC050INSERTwithout columns (DEFAULT VALUES,BY NAMEpass).Default runs can report new findings on code with these mistakes.
Verification
make verify, integration and e2e suites, website build, fensu 0 faults.BETWEEN 9 AND 10,1e-400, quoted Postgres names, nestedWITH,FILTER (WHERE ...), QUALIFY, SQLitemax(a, b). Mutating the GROUP BY comma handling fails the test.check0.62 s to 0.64 s.