SQL style rules
Standing rules for SQL an assistant writes, covering formatting, naming, explicit column lists, parameterised queries, NULL handling, data types and safe migrations.
When you write or change SQL in this project:
Dialect and formatting
- Write for the project's database engine and version. Do not use features it lacks, and flag engine-specific syntax when portability matters.
- Match the existing formatting. Where there is none: uppercase keywords, one major clause per line (
SELECT,FROM,JOIN,WHERE,GROUP BY,ORDER BY), one column per line in long lists, and consistent indentation. - Prefer common table expressions to deeply nested subqueries, with names that say what each step contains.
- Comment the reason for non-obvious logic, not what the SQL does.
Naming
- Use
snake_casewith no quoted identifiers, reserved words or unexplained abbreviations. Follow the existing singular or plural convention for table names. - Name foreign keys
<referenced_table>_id, booleansis_orhas_, timestamps_atand dates_onor_date. - Name constraints and indexes explicitly (
orders_customer_id_fkey,orders_created_at_idx) so migrations can refer to them.
Queries
- List columns explicitly in
SELECTandINSERT. UseSELECT *only in ad hoc exploration, never in application code, views or models. - Use explicit
JOIN ... ON, never comma joins, and qualify every column with a table alias when more than one table is involved. - Add
ORDER BYwhenever the order matters, and always withLIMITorOFFSET. Make the ordering deterministic with a unique tie-breaker. - Check for fan-out before aggregating over joins, and aggregate before joining when that avoids it.
Parameters and safety
- Pass values as bound parameters, always. Never build SQL by concatenating or interpolating user input.
- When an identifier such as a sort column must be dynamic, choose it from an allowlist in code.
- Grant application roles only the privileges they need.
NULLs and types
- Compare with
IS NULLorIS DISTINCT FROM, never= NULL. PreferNOT EXISTStoNOT INwhen the subquery can return NULL. - Store money as
NUMERIC/DECIMALor integer minor units, never floating point. Store timestamps with time zone, in UTC. - Enforce integrity in the schema with
NOT NULL,CHECK,UNIQUEand foreign keys, not only in application code.
Migrations
- One logical change per migration. Never edit a migration that has already run anywhere shared; write a new one.
- Separate schema changes from data backfills. Run backfills in batches with short transactions.
- On large or busy tables, use lock-safe forms: build indexes concurrently or online, add constraints without validation and validate them separately, add columns as nullable first, and set a lock timeout.
- Make destructive changes (drop, rename, type narrowing) only after a release in which no deployed code uses the old shape, and give every migration a tested rollback or an explicit note that it cannot be reversed.
details
- kind
- Rule: standing instructions for everything the assistant does
- domain
- Software engineering
- category
- Conventions
- made for
- Backend engineer, Data engineer, Database administrator, Data analyst
- risk
- read-only
- version
- v1.0.0 · experimental
- reviewed
- 2026-10-02
- works in
- Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai
use in
npx @hermes-hq/hodios install sql-style-rules --target claude-codenpx skills add hermes-hq/hodios-dist --skill sql-style-rules -a claude-codeRules are always-on instructions, so they are not in the plugins: add the skill, or paste the text into CLAUDE.md.
more in conventions
All of ConventionsHTTP API design rules
Rules for HTTP APIs covering resource naming, status codes, problem+json errors, cursor pagination, idempotency keys and versioning. Load when designing or changing HTTP endpoints.
api-design-rulesC# style rules
Standing rules for C# an assistant writes, covering nullable reference types, async all the way with cancellation tokens, records and pattern matching, dependency injection and xUnit tests.
csharp-style-rulesGo style rules
Standing rules for Go an assistant writes, covering wrapped errors, context propagation, small consumer-side interfaces, table-driven tests and no goroutines without an owner.
go-style-rulesJava style rules
Standing rules for Java an assistant writes, covering modern language features, immutability, Optional and null handling, exceptions, restrained streams, records and JUnit 5 tests.
java-style-rulesPython style rules
Standing rules for Python an assistant writes, covering type hints, pathlib, logging over print, explicit exceptions, safe subprocess calls, project layout and the project's own tooling.
python-style-rulesReact component rules
Standing rules for React code an assistant writes, covering function components, the rules of hooks, colocated state, stable list keys, accessible markup and no effect-driven derived state.
react-component-rules