sqlfluff-check

sqlfluff syntax check and fix tool. Used to run sqlfluff to check and fix syntax issues in SQL files, suitable for syntax validation and automatic fixes of migration files and various SQL scripts.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "sqlfluff-check" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-eb6e51632c5974ab5e9760d5d10d84ecc3b63412ebb02114b98e04be84727775. Verify the upstream source and version against https://skillhub.cn/skills/user_0a862de7/sqlfluff-check before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

sqlfluff syntax check and fix tool. Used to run sqlfluff to check and fix syntax issues in SQL files, suitable for syntax validation and automatic fixes of migration files and various SQL scripts.

0 Downloads

Introduction source: third_party · user_0a862de7 · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Limits and differences
line_length_limit = 120
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: sqlfluff-check
description: 使用 sqlfluff 检查和修复 SQL 文件语法错误。当需要检查迁移文件、SQL 脚本语法时使用。
version: 1.0.0
metadata:
  clawdbot:
    emoji: "🔍"
    requires:
      anyBins: ["sqlfluff"]
    os: ["linux", "darwin"]

SQL 检查与修复助手

触发条件

当用户出现以下意图时激活本 Skill:

  • 检查 SQL 文件语法
  • 修复 SQL 语法错误
  • SQL lint 检查
  • 数据库迁移文件验证

使用方法

1. 检查 SQL 文件(只读)

# 检查单个文件
sqlfluff lint <file.sql> --dialect postgres

# 检查目录下所有 SQL 文件
sqlfluff lint <directory> --dialect postgres

# 检查迁移文件
sqlfluff lint migrations/ --dialect postgres

2. 自动修复 SQL 文件

# 修复单个文件
sqlfluff fix <file.sql> --dialect postgres

# 修复目录下所有 SQL 文件
sqlfluff fix <directory> --dialect postgres

# 修复迁移文件
sqlfluff fix migrations/ --dialect postgres --force

3. 查看配置

# 显示当前配置
sqlfluff config

# 显示将要应用的规则
sqlfluff rules

配置说明

项目根目录应有 .sqlfluff 配置文件:

[sqlfluff]
dialect = postgres
exclude_rules = all
templater = raw
disable_templating = true

# 行长度限制
line_length_limit = 120
# 缩进
indent_width = 4
indent_unit = space
# 关键字大写
capitalisation_policy = upper

常见错误类型及修复

1. 标点符号错误

问题:外键约束中逗号位置错误

-- 错误
CONSTRAINT fk_xxx, FOREIGN KEY (col), REFERENCES table(col)

-- 正确
CONSTRAINT fk_xxx FOREIGN KEY (col) REFERENCES table(col)

2. VALUES 列表长度不一致

问题:INSERT 语句中列数与值数不匹配

-- 错误(6列但只有5个值)
INSERT INTO table (a, b, c, d, e, f) VALUES ('val1', 'val2', 'val3', 'val4', 'val5')

-- 正确
INSERT INTO table (a, b, c, d, e, f) VALUES ('val1', 'val2', 'val3', 'val4', 'val5', 'val6')

3. ON CONFLICT 规范不匹配

问题:ON CONFLICT 指定的列没有唯一约束

-- 错误(如果 (col) 没有唯一约束)
INSERT INTO table (...) VALUES (...) ON CONFLICT (col) DO NOTHING

-- 正确(使用 DO NOTHING 或确保列有唯一约束)
INSERT INTO table (...) VALUES (...) ON CONFLICT DO NOTHING

4. psql 变量语法错误

问题:psql 变量引用格式不正确

-- 错误
: variable_name
':variable_name'

-- 正确
:variable_name        -- 数值变量
:'variable_name'      -- 字符串变量

执行流程

1. 定位目标文件/目录
2. 运行 sqlfluff lint 检查
3. 分析错误报告
4. 手动修复或运行 sqlfluff fix
5. 验证修复结果

批量修复脚本

# 修复所有迁移文件
find migrations/ -name "*.sql" -exec sqlfluff fix {} --dialect postgres --force \;

# 只检查不修复
sqlfluff lint migrations/ --dialect postgres 2>&1 | tee /tmp/sqlfluff-report.txt

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 提供 SQL 语法检查与修复功能,面向数据库开发和迁移文件验证等明确场景
  • 具有广泛实用价值,属于通用工具范畴
Trigger Precision90/100

Highlights

  • description 明确描述了使用场景,触发条件覆盖多种用户意图
  • 边界清晰,不易与其他 Skill 重叠
Structure and Standards95/100

Highlights

  • 文档结构完整,包含触发条件、使用方法、配置说明、常见错误类型及修复、执行流程等
  • frontmatter 完整,单文件未超过 500 行
Execution Reliability88/100

Highlights

  • 工具来源明确(sqlfluff),参数使用正确
  • 提供了检查和修复两种模式,覆盖了常见异常场景
  • 批量修复脚本增加了实用性
Evidence Verifiability (mean of the first four)90/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.