Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

pg-data

БесплатноБез исполняемых скриптовНе проверен

Generate safe, read-only PostgreSQL queries from natural language. Use when users need to query blog_small, ecommerce_medium, or saas_crm_large databases…

tyrchenот tyrchen★ 237 звёзд на GitHub19 установок в других каталогах

Об этом скилле

PostgreSQL Data Query Generator

Generate safe, production-ready PostgreSQL SELECT queries from natural language descriptions. This skill analyzes user requests, matches them to the appropriate database schema, generates secure SQL, tests execution, and validates results.

When to Use This Skill

Use this skill when the user wants to:

  • Query data from blog_small, ecommerce_medium, or saas_crm_large databases
  • Analyze data with aggregations, joins, or complex filters
  • Generate reports from the available databases
  • Explore database content through natural language queries

Available Databases

Database Description Use Cases
blog_small Blog platform with users, posts, comments, categories, tags Content analytics, author stats, engagement metrics
ecommerce_medium E-commerce with products, orders, inventory, reviews Sales analysis, inventory management, customer insights
saas_crm_large Multi-tenant CRM with leads, deals, accounts, tickets Pipeline analysis, sales performance, support metrics

Security Requirements

CRITICAL: All generated SQL must comply with these security rules:

Allowed Operations

  • SELECT statements only
  • Read-only aggregate functions (COUNT, SUM, AVG, MIN, MAX, etc.)
  • JOINs, subqueries, CTEs, window functions
  • WHERE, GROUP BY, HAVING, ORDER BY, LIMIT clauses

Prohibited Operations

  • NO INSERT, UPDATE, DELETE, TRUNCATE, DROP, ALTER, CREATE
  • NO EXECUTE, CALL, DO blocks
  • NO pg_sleep, pg_terminate_backend, or any system functions
  • NO COPY, \copy, or file operations
  • NO SET, RESET, or configuration changes
  • NO Comments containing sensitive data
  • NO Dynamic SQL or string concatenation for queries
  • NO Access to pg_catalog system tables (except for metadata queries)
  • NO Sensitive data exposure (passwords, API keys, tokens, hashes)

SQL Injection Prevention

  • Use parameterized queries when possible
  • Validate and sanitize any user-provided values
  • Never concatenate user input directly into SQL
  • Escape special characters properly

Workflow

Step 1: Analyze User Request

Parse the user's natural language query to determine:

  1. Target database: Which database(s) does this query relate to?

    • Blog content, posts, comments, authors → blog_small
    • Products, orders, sales, inventory, reviews → ecommerce_medium
    • Leads, deals, accounts, contacts, tickets, subscriptions → saas_crm_large
  2. Query intent: What data does the user want?

    • Listing/searching records
    • Aggregation/statistics
    • Relationships/joins
    • Time-based analysis
  3. Output format: Does the user want SQL only or results?

    • If user says "give me the SQL" or "show me the query" → Return SQL only
    • Otherwise → Execute and return results (default)

Step 2: Read Database Reference

Read the appropriate reference file(s) to understand the schema:

# Read the reference file for the target database
cat .claude/skills/pg-data/references/<database_name>.md

Reference files contain:

  • Table structures with columns and types
  • Foreign key relationships
  • Available views
  • Common query patterns

Step 3: Generate SQL

Generate a SQL query following these guidelines:

  1. Start with the primary table that best matches the user's intent
  2. Add JOINs only when necessary for the requested data
  3. Use appropriate indexes - check the reference for available indexes
  4. Include sensible defaults:
    • Add LIMIT 100 for unbounded queries
    • Use meaningful column aliases
    • Order results logically

SQL Template

-- Purpose: <brief description of what this query does>
SELECT
    <columns with meaningful aliases>
FROM <primary_table> <alias>
[JOIN <related_table> ON <condition>]
[WHERE <filters>]
[GROUP BY <grouping>]
[HAVING <aggregate_filters>]
[ORDER BY <ordering>]
[LIMIT <reasonable_limit>];

Step 4: Validate SQL Safety

Before execution, verify the query:

  1. Check for prohibited keywords:

    INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, TRUNCATE,
    EXECUTE, CALL, DO, COPY, SET, RESET, pg_sleep, pg_terminate
    
  2. Verify read-only nature: Query must only retrieve data

  3. Check for sensitive data exposure: Exclude password_hash, api_key, token fields

Step 5: Execute and Test

Execute the SQL using psql:

PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d <database_name> -c "<SQL_QUERY>"

If execution fails:

  1. Analyze the error message
  2. Check for:
    • Invalid column/table names
    • Type mismatches
    • Syntax errors
    • Missing JOINs
  3. Regenerate the SQL with corrections
  4. Return to Step 5 (max 3 retries)

Step 6: Analyze Results and Score Confidence

Evaluate the query results and assign a confidence score (0-10):

Score Meaning Action
10 Perfect match, expected resul
Полный SKILL.md на GitHub

Установить pg-data в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/blog_small.mdreferences/ecommerce_medium.mdreferences/saas_crm_large.md

FAQ

Что делает скилл pg-data?

Generate safe, read-only PostgreSQL queries from natural language. Use when users need to query blog_small, ecommerce_medium, or saas_crm_large databases. Supports query generation, execution, and result analysis with confidence scoring.

Как установить скилл pg-data?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл pg-data запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить pg-data с