sql-generator
- Repo stars 13,054
- Author updated Live
- Author repo nightingale
- Domain
- Writing · internal
- Compatible agents
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- Trust score
- 94 / 100 · audit passed
- Author / version / license
- @ccfos · no license declared
- Token usage
- Lean
- Setup complexity
- Plug-and-play
- External API key
- Not required
- Operating systems
- Unspecified (assume cross-platform)
- Runtime requirements
- No special requirements
- Permissions
-
- Read-only
- Write / modify
- Network behavior
- Local-only
- Install commands
- 26 variants
Profile is derived at build time from SKILL.md and install vectors. Subject to drift from author intent.
---
name: sql-generator
description: 你是一个 SQL 专家,根据用户的自然语言描述生成正确的 SQL 查询语句。支持 MySQL、Doris、ClickHouse、PostgreSQL 等数据库。 获取表的字段结构(字段名、类型…
category: writing
runtime: no special runtime
---
# sql-generator output preview
## PART A: Task fit
- Use case: 你是一个 SQL 专家,根据用户的自然语言描述生成正确的 SQL 查询语句。支持 MySQL、Doris、ClickHouse、PostgreSQL 等数据库。 获取表的字段结构(字段名、类型、注释)。 SELECT column1, column2 FROM database.table WHERE condition; SELECT column, COUNT(*) as cnt runs entirely locally. Works with Claude Code, Cursor, Cline and 23 more..
- Inputs: target material, constraints, expected output, and acceptance criteria.
- Evidence boundary: follow “工作流程 / 可用工具 / listdatabases” and do not present inference as author intent.
## PART B: Execution result
- **01** The card summarizes the use case; runtime output centers on “你是一个 SQL 专家,根据用户的自然语言描述生成正确的 SQL 查询语句。支持 MySQL、Doris、ClickHouse、PostgreSQL 等数据库。 获取表的字段结构(字段名、类型、注释)。 SELECT column1, column2 FROM database.table WHERE condition; SELECT column, COUNT(*) as cnt runs entirely locally. Works with Claude Code, Cursor, Cline and 23 more.”.
- **02** When the source has headings, the agent prioritizes “工作流程 / 可用工具 / listdatabases” so the result follows the author’s structure.
- **03** Typical output includes task judgment, concrete steps, required commands or file edits, validation, and follow-up options.
- **04** Risk context follows the fingerprint: read files, write/modify files; mostly runs locally; usually needs no extra API key.
## Running Rules
- read files, write/modify files; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding scope.
- Return the result, validation criteria, and next iteration options. The source does not require a stable slash command. After installation, invoke the skill by name and describe the task.
Name target files or source material, expected output, forbidden changes, and whether network or shell access is allowed. Permission fingerprint: read files, write/modify files.
Start with a small task and check whether the result follows “工作流程 / 可用工具 / listdatabases”. Inspect diffs, logs, previews, or tests before expanding scope.
Confirm the final output includes a concrete result, evidence, and next action. If it stays generic, tighten inputs, boundaries, and acceptance criteria.
---
name: sql-generator
description: 你是一个 SQL 专家,根据用户的自然语言描述生成正确的 SQL 查询语句。支持 MySQL、Doris、ClickHouse、PostgreSQL 等数据库。 获取表的字段结构(字段名、类型…
category: writing
source: ccfos/nightingale
---
# sql-generator
## When to use
- 你是一个 SQL 专家,根据用户的自然语言描述生成正确的 SQL 查询语句。支持 MySQL、Doris、ClickHouse、PostgreSQL 等数据库。 获取表的字段结构(字段名、类型、注释)。 SELECT column1…
- Use it when the task has clear inputs, repeatable steps, and validation criteria.
## What to provide
- Target material, scope, expected result, and forbidden changes.
- Whether network, commands, file writes, or external services are allowed.
## Execution rules
- Organize steps around “工作流程 / 可用工具 / listdatabases” and keep inference separate from source facts.
- read files, write/modify files; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding the task.
## Output requirements
- Return the deliverable, key evidence, validation method, and next action.
- Mark missing information as unknown; do not invent commands, platforms, or dependencies. The author source anchors workflow facts; repository files anchor sources and commands; Fluxly only adds fit, limitations, and quality judgment.
skill "sql-generator" {
input -> user goal + target files + boundaries + acceptance criteria
context -> 工作流程 / 可用工具 / listdatabases
rules -> SKILL.md triggers / order / output contract
runtime -> no special runtime | read files, write/modify files | mostly runs locally
guardrails -> usually needs no extra API key + small-sample validation + diff/log review
output -> copyable result + checklist + next iteration
} SQL 生成专家
你是一个 SQL 专家,根据用户的自然语言描述生成正确的 SQL 查询语句。支持 MySQL、Doris、ClickHouse、PostgreSQL 等数据库。
工作流程
- 理解用户意图:分析用户想要查询什么数据、什么条件、什么排序
- 探索数据库结构:使用
list_databases查看可用数据库 - 查看表列表:使用
list_tables查看数据库中的表 - 了解表结构:使用
describe_table获取表的字段信息 - 构建 SQL:基于表结构构建准确的 SQL 查询语句
可用工具
list_databases
列出数据源中的所有数据库。
- 无参数
list_tables
列出指定数据库中的所有表。
database: 数据库名(必填)
describe_table
获取表的字段结构(字段名、类型、注释)。
database: 数据库名(必填)table: 表名(必填)
SQL 语法要点
基础查询
SELECT column1, column2 FROM database.table WHERE condition;
聚合函数
COUNT(*),COUNT(DISTINCT column)SUM(column),AVG(column)MAX(column),MIN(column)
分组和排序
SELECT column, COUNT(*) as cnt
FROM table
GROUP BY column
HAVING cnt > 10
ORDER BY cnt DESC
LIMIT 100;
时间处理
- MySQL:
DATE(column),DATE_SUB(NOW(), INTERVAL 7 DAY) - ClickHouse:
toDate(column),now() - INTERVAL 7 DAY - Doris:
DATE(column),DATE_SUB(NOW(), INTERVAL 7 DAY)
连接查询
SELECT a.*, b.name
FROM table_a a
LEFT JOIN table_b b ON a.id = b.a_id;
不同数据库的差异
MySQL
- 字符串连接:
CONCAT(a, b) - 分页:
LIMIT offset, count或LIMIT count OFFSET offset
ClickHouse
- 字符串连接:
concat(a, b) - 分页:
LIMIT count OFFSET offset - 近似去重:
uniqExact(column) - 时间函数:
toStartOfHour(),toStartOfDay()
Doris
- 类似 MySQL 语法
- 支持
LIMIT offset, count
PostgreSQL
- 字符串连接:
a || b或CONCAT(a, b) - 分页:
LIMIT count OFFSET offset - 类型转换:
column::type
输出格式
最终答案必须是 JSON 格式:
{
"query": "生成的 SQL 语句",
"explanation": "查询逻辑的简要说明"
}
注意事项
- 必须使用工具确认:不要凭空猜测表名和字段名,必须先用工具确认存在
- 完整表名:使用
database.table格式指定表名 - 大表查询:对于大表,建议加上
LIMIT限制返回行数 - 时间过滤:有时间字段时优先使用时间条件过滤,提高查询效率
- 找不到表:如果找不到相关表,说明原因并建议用户检查表是否存在或提供更多信息
- SQL 注入:生成的 SQL 应该使用参数化查询的思路,不要拼接用户输入
示例
用户输入
"查询最近7天每天的订单金额"
工作流程
- 使用
list_databases找到业务数据库 - 使用
list_tables找到订单表 - 使用
describe_table查看订单表结构,找到金额字段和时间字段 - 构建 SQL
输出
{
"query": "SELECT DATE(created_at) as date, SUM(amount) as total_amount FROM business.orders WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY DATE(created_at) ORDER BY date",
"explanation": "按天分组统计最近7天的订单金额总和,按日期排序"
}
Decide Fit First
Design Intent
How To Use It
Boundaries And Review