CockroachDB SQL Skill
Converts natural language questions into CockroachDB-compliant SQL queries, following CockroachDB best practices. Use it for schema design, writing queries and optimizing query.
How to Apply this Skill
-
Connection Detection — already performed on skill invocation; reuse active connection.
-
Parse Natural Language Intent
- Identify the operation type (SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, etc.)
-
Context Gathering
- Check for existing schema context in conversation
- If connected to DB, query existing schema:
SHOW TABLES;to see existing tablesSHOW CREATE TABLE table_name;for existing structure
- Ask clarifying questions if needed:
- Table structure if not provided
- Data types for columns
- Index requirements
- Multi-region needs
- Performance characteristics
-
Apply CockroachDB Rules
- Reference rules in
references/cockroachdb-rules/ - Ensure compliance with CockroachDB best practices
- Determine rule category based on operation and apply the relavant rules:
00-fundamental-principles.md- Always apply these first01-schema-design.md- Table creation and structure02-dml-operations.md- Data modification03-query-patterns.md- Query construction04-optimization.md- Performance, Optimization and anti-patterns05-operational.md- Admin and maintenance
- Validate against anti-patterns in 04-optimization.md
- Reference rules in
-
Validate against DB(MANDATORY)
- ALWAYS run EXPLAIN on every generated SQL query when connected to DB.
- If EXPLAIN returns a parsing/syntax error, fix the query and re-run EXPLAIN until it passes.
- Include the EXPLAIN output in the response.
Response Behavior
Initial Response
When skill is invoked:
-
Check for an available connection so queries run against the right cluster:
- Check if a connection string is provided in the prompt (postgresql://...).
- If provided, use
cockroach sql --url "<provided-url>" -e "SQL"to run queries. Do not use psql.
- If provided, use
- Else check the COCKROACH_URL environment variable (
echo $COCKROACH_URL).- If set, use
cockroach sql --url $COCKROACH_URL -e "SQL"to run queries. Do not use psql.
- If set, use
- Else check for cockroach-cloud MCP server availability.
- If none of these are available or it is unclear which cluster to use, ask the user before running anything.
- Check if a connection string is provided in the prompt (postgresql://...).
-
Focus exclusively on CockroachDB
-
Emphasize "natural language to CockroachDB SQL" not "database conversion"
-
Present CockroachDB-specific syntax even when a rule derives from PostgreSQL compatibility.
Output Format
- Show generated SQL with explanatory comments
- List CockroachDB-specific features used
- Include performance considerations
- When optimizing, at each step 1- Explain the step's purpose. 2- Execute the step and report the outcome. 3- Summarize all findings and actions taken.
- Provide references used including the rules
Examples
Schema Design — UUID Primary Key (Avoid Hotspots)
Batch Upsert with UNNEST
Keyset Pagination (Avoid OFFSET)
Use the previous page's last (created_at, id) as the cursor. In application code these are bound parameters; the literals here are placeholders.
Supporting Documentation
references/cockroachdb-rules/- CockroachDB SQL rulesreferences/EXAMPLES.md- SQL examples and patterns

