Rules Hub
Code Ruleset
← 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 ruleP2universalStack: SQL
sqlreadabilityquery-building
Alias aggregate/computed columns in SQL results
Give aggregate expressions a clear alias (COUNT(...) AS total) so the result property name is meaningful instead of the raw expression text.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codesql
| 1 | SELECT COUNT(DISTINCT(main_profiles.id)) FROM main_profiles |
Explanation (EN)
A driver-generated expression name is awkward and can change when the query changes.
Objašnjenje (HR)
Good example
New codesql
| 1 | SELECT COUNT(DISTINCT(main_profiles.id)) AS mainProfilesIdCount FROM main_profiles |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For an aggregate selected into application code, give the result a stable descriptive alias and align the consumer type with the database return type.
Exceptions / Tradeoffs (EN)
Preserve an existing public result-field contract or migrate callers together.