Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/hamzaamjad/cursor-rulesWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/hamzaamjad/cursor-rules/212-sql-correctness)<a href="https://agentmods.dev/rules/hamzaamjad/cursor-rules/212-sql-correctness"><img src="https://agentmods.dev/badge/rules/hamzaamjad/cursor-rules/212-sql-correctness/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/rules/hamzaamjad/cursor-rules/212-sql-correctness"><img src="https://agentmods.dev/badge/rules/hamzaamjad/cursor-rules/212-sql-correctness.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00000 | $0.00901 |
| Opus 5.5 | $0.00000 | $0.00360 |
| Sonnet 5.5 | $0.00000 | $0.00180 |
| Haiku 4.5 | $0.00000 | $0.00090 |
Grade A, and why
212-sql-correctness scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
sql-correctness.mdc
- Purpose: To guide AI assistants and developers in writing correct and robust SQL queries, paying attention to dialect specifics and common pitfalls.
- Requirements:
- Dialect Awareness:
- Explicitly confirm the target SQL dialect (e.g., Redshift, PostgreSQL, MySQL, BigQuery, Snowflake).
- Verify function usage against the specific dialect's documentation, especially for date/time manipulation (e.g.,
DATEADD/DATE_ADD/+ INTERVAL,DATEDIFF,GETDATE/NOW/CURRENT_TIMESTAMP), string manipulation, and JSON functions.
- Join Logic:
- Verify join types (
INNER,LEFT,RIGHT,FULL OUTER) match the intended logic for handling matching and non-matching rows. - Ensure join conditions (
ONclause) correctly link tables using appropriate keys and comparisons. Avoid unintentional cross joins.
- Verify join types (
- Column References:
- Qualify column names with table aliases or full table names when multiple tables are involved to avoid ambiguity.
- Double-check column names for typos against the source schema.
- Filtering:
- Ensure
WHEREclauses accurately reflect the desired filtering conditions. - Be mindful of
NULLhandling in comparisons (useIS NULL/IS NOT NULL).
- Ensure
- Aggregation & Window Functions:
- Verify
GROUP BYclauses include all non-aggregated columns in theSELECTlist (unless the dialect permits otherwise). - Ensure window function
PARTITION BYandORDER BYclauses are correctly specified for the intended calculation. - Redshift Specific: Avoid using
COUNT(DISTINCT col) OVER (PARTITION BY ...)due to potential parser limitations. Instead, pre-aggregate data to the required grain in a preceding CTE to ensure distinctness, then useCOUNT(*) OVER (PARTITION BY ...)on the pre-aggregated data.
- Verify
- Output Ordering:
- Include an
ORDER BYclause for finalSELECTstatements intended for human consumption or reporting to ensure deterministic results, unless ordering is irrelevant or handled downstream.
- Include an
- Syntax & Formatting:
- Validate overall query syntax against the target dialect.
- Maintain consistent formatting (indentation, capitalization of keywords) for readability. Refer to
sql-performance.mdcfor performance-related style.
- Dialect Awareness:
- Validation:
- Check: Is the target SQL dialect mentioned or assumed correctly?
- Check: Are dialect-specific functions used appropriately? (e.g., Redshift
DATEADDvs. PostgreSQL interval math). - Check: Is join logic clear and likely correct? Are columns qualified?
- Check: Does the query include an
ORDER BYclause if the output is likely for reporting? - Check: Is the syntax valid for the target platform?
- Examples:
- Scenario: Calculating days between two dates in Redshift.
- Weak (PostgreSQL style):
SELECT end_date - start_date FROM my_table; - Improved (Redshift style):
SELECT DATEDIFF(day, start_date, end_date) FROM my_table;
- Weak (PostgreSQL style):
- Scenario: Getting user name but handling missing users.
- Weak (Might error or lose rows on INNER JOIN):
SELECT o.order_id, u.name FROM orders o JOIN users u ON o.user_id = u.id; - Improved (Handles missing users):
SELECT o.order_id, COALESCE(u.name, 'Unknown') FROM orders o LEFT JOIN users u ON o.user_id = u.id;
- Weak (Might error or lose rows on INNER JOIN):
- Scenario: Calculating days between two dates in Redshift.
- Changes: Updated to include recent SQL dialects and best practices for ensuring SQL correctness, including handling of JSON data types and new window functions.
- Source References: Retrospective from GTM compensation SQL task (July 2024).
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 44 lines · 0 tokens per session scan A 579a46ace1bb
212-sql-correctness is a cursor rule published in the GitHub repository hamzaamjad/cursor-rules (2 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 901 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other cursor rules, from other repositories
as-contract-cast-smell
// ❌ WRONG — bypasses the family ContractSerializer seam const contract = JSON.parse(raw) as Contract; const contract = JSON.parse(raw) as Contract .
no-backward-compatibility
Do not add backward-compatibility shims or migration scaffolding.
postgresql
This guide defines the definitive best practices for writing clean, performant, and maintainable PostgreSQL SQL, focusing on modern conventions and avoiding common pitfalls.
ehs-ims-conventions
EHS IMS app — RBAC, data layer, tRPC, migrations, AI boundaries.
sync-timedb-archive-janitor-contract
Day-close / cold-path worker contracts for synctimedb (A invariants; B tick coordinator retired).
schema
Scalable and secure schema design patterns for relational databases, NoSQL, and APIs. / TR: İlişkisel veri tabanları, NoSQL ve API'ler için ölçeklenebilir ve güvenli şema tasarım kalıpları.