home / skills / openclaw / skills / ai-sql
This skill converts natural language into optimized SQL queries across dialects, handling joins and conditions to accelerate data retrieval.
npx playbooks add skill openclaw/skills --skill ai-sqlReview the files below or copy the command above to add this skill to your agents.
---
name: sql-gen
description: Generate SQL queries from natural language
---
# SQL Generator
Describe what you want, get the SQL. Works with any database.
## Quick Start
```bash
npx ai-sql "get all users who signed up this month and made a purchase"
```
## What It Does
- Converts English to SQL
- Handles complex JOINs
- Adds proper WHERE clauses
- Optimizes for performance
## Usage Examples
```bash
# Generate query
npx ai-sql "top 10 products by revenue last quarter"
# With schema context
npx ai-sql "users without orders" --schema ./schema.sql
# Specific dialect
npx ai-sql "monthly active users" --dialect postgres
```
## Dialects Supported
- PostgreSQL
- MySQL
- SQLite
- SQL Server
- Oracle
## Output Example
```sql
SELECT u.id, u.email, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.created_at >= DATE_TRUNC('month', CURRENT_DATE)
GROUP BY u.id, u.email
HAVING COUNT(o.id) > 0;
```
## Requirements
Node.js 18+. OPENAI_API_KEY required.
## License
MIT. Free forever.
---
**Built by LXGIC Studios**
- GitHub: [github.com/lxgicstudios/ai-sql](https://github.com/lxgicstudios/ai-sql)
- Twitter: [@lxgicstudios](https://x.com/lxgicstudios)
This skill turns plain English prompts into runnable SQL queries for a wide range of SQL dialects. It helps developers and analysts rapidly prototype queries, handle joins and aggregations, and tailor output to a target database dialect. Use it to save time and reduce manual query errors.
You provide a natural language description of the data you need and optionally supply a schema file or select a dialect. The skill parses intent, maps terms to tables and columns, constructs JOINs, WHERE clauses, GROUP BY and HAVING as needed, and outputs an optimized SQL statement. It supports dialect-specific syntax and can prioritize performance-friendly constructs.
Which SQL dialects are supported?
Common dialects are supported including PostgreSQL, MySQL, SQLite, SQL Server, and Oracle.
Can I provide a schema so the skill uses real column names?
Yes. Supplying a schema file or DDL improves accuracy by allowing the generator to map natural language to actual tables and columns.
Is the generated SQL production-ready?
Generated SQL is intended to be syntactically correct and performance-conscious, but you should validate and test queries in your environment before production use.