sql-insight

Translate natural language to SQL and analyze query plans for SQLite and PostgreSQL.

4.6k|462|Updated Jun 21, 2025
One-click install
npx skills add https://github.com/zebbern/claude-code-guide --skill sql-insight
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-insight
Source: https://github.com/zebbern/claude-code-guide/tree/main/skills/sql-insight
Command: npx skills add https://github.com/zebbern/claude-code-guide --skill sql-insight

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires psycopg2-binary, and includes scripts (resource) components.

What problem does it solve?

Writing correct and performant SQL requires knowing the database schema and understanding execution plans, which is time-consuming when working with unfamiliar SQLite or PostgreSQL databases.

Core Features & Use Cases

  • Schema Extraction: Extracts tables, columns, indexes, foreign keys, and sample rows into JSON or a compact text format suitable for LLM prompts.
  • Rule-Based Query Optimization: Detects 13 SQL anti-patterns such as SELECT *, leading-wildcard LIKE, NOT IN subqueries, and functions on indexed columns, without needing a database connection.
  • EXPLAIN Plan Interpretation: Runs EXPLAIN (or EXPLAIN ANALYZE on PostgreSQL) and flags full table scans, disk sorts, nested loop joins, and row estimate deviations.
  • Use Case: Given a SQLite file, extract its schema in compact mode, generate a query from a natural language question, then verify the query uses an index instead of a full table scan before running it in production.

Quick Start

Ask the assistant to extract the schema from your SQLite database file and turn your question into an optimized SQL query with an explained execution plan.

Frequently Asked Questions about sql-insight

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert natural language to SQL with schema context?

Extract the database schema first using the schema command with the --compact flag, which produces a concise text summary of tables, columns, indexes, and foreign keys. Feed that schema into the prompt so the generated SQL references real table and column names.

How can I detect SQL anti-patterns without a database connection?

Run the optimize subcommand with any SQL string; it applies 13 rule-based checks such as SELECT *, leading-wildcard LIKE, and NOT IN subqueries entirely offline. It returns JSON issues with severity, message, and a concrete suggestion.

Does this tool support PostgreSQL as well as SQLite?

Yes, both databases are supported. SQLite connects to a local file via --db-path, while PostgreSQL requires a DSN passed with --dsn and the psycopg2-binary package installed. PostgreSQL also supports EXPLAIN ANALYZE for actual runtime statistics.

Is it safe to run EXPLAIN against a production database?

Connections are opened read-only: SQLite uses mode=ro and PostgreSQL sets the session to read only. Only SELECT, WITH, and EXPLAIN statements are allowed, write keywords and multi-statement input are blocked, and identifiers are escaped.

Why does my query trigger a full table scan warning?

A full table scan appears when the WHERE or JOIN columns lack a usable index, or when functions are applied to indexed columns. The interpretation output names the scanned table and suggests adding an index on the filtered columns.