Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: SQL
sqlnull-handlingaggregatescorrectness
Wrap nullable SQL aggregates/expressions in COALESCE
When an aggregate or arithmetic on possibly-null columns can yield NULL, wrap it in COALESCE so the query returns a sensible default rather than null.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codesql
| 1 | SELECT summary.total - returned.total AS net FROM ... |
Explanation (EN)
Objašnjenje (HR)
Good example
New codesql
| 1 | SELECT COALESCE(summary.total, 0) - COALESCE(returned.total, 0) AS net FROM ... |
Explanation (EN)
Objašnjenje (HR)