postgres-query-expert

Construct and optimize PostgreSQL 16 SQL queries with parameterization and EXPLAIN ANALYZE.

49|9|Updated Dec 18, 2025
One-click install
npx skills add https://github.com/ratacat/claude-skills --skill postgres-query-expert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-query-expert
Source: https://github.com/ratacat/claude-skills/tree/main/skills/postgres-query-expert
Command: npx skills add https://github.com/ratacat/claude-skills --skill postgres-query-expert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

A comprehensive reference for PostgreSQL 16, covering query construction, optimization, schema management, and introspection.

Core Features & Use Cases

  • ANSI SQL with PostgreSQL extensions (DISTINCT ON, RETURNING, LATERAL, etc.)
  • Introspection queries to list tables and columns
  • Advanced features: MERGE, window functions, JSONB, arrays, ranges
  • DML patterns with RETURNING and transactional guidance

Quick Start

Example: connect to your DB and run a sample query via psql

  • psql -d mydb -c "SELECT version();"

Frequently Asked Questions about postgres-query-expert

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

FAQPage Schema
How do I optimize slow PostgreSQL queries?

Query optimization in PostgreSQL involves analyzing execution plans with EXPLAIN ANALYZE, adding indexes on frequently filtered columns, and rewriting queries to reduce scans. This Skill provides indexing recommendations, schema introspection to identify bottlenecks, and patterns for window functions and DISTINCT ON to improve performance across PostgreSQL 16 deployments.

What's the best way to construct complex SQL queries in PostgreSQL?

PostgreSQL 16 supports ANSI SQL plus extensions like RETURNING, LATERAL, MERGE, and JSONB operations for building advanced queries. This Skill covers parameterized query construction using $1, $2 syntax, transactional patterns with BEGIN/COMMIT, and DML operations that safely return modified rows.

How do I use MERGE and RETURNING in PostgreSQL?

MERGE performs conditional insert, update, or delete in a single statement, while RETURNING retrieves modified rows without extra queries. Both are PostgreSQL 16 extensions covered here with transactional safety, parameterized construction, and practical DML patterns for schema management.

Can I use window functions and arrays with PostgreSQL queries?

PostgreSQL 16 supports window functions for ranking and aggregation, array and range types, and JSONB for semi-structured data. This Skill implements these advanced features alongside schema introspection and performance tuning for production deployments.

How do I debug PostgreSQL query errors and performance issues?

Debug PostgreSQL queries using EXPLAIN ANALYZE to view execution plans, schema introspection to verify table and column structure, and statement timeout settings via SET LOCAL. This Skill provides error diagnosis, indexing recommendations, and best practices for parameterized, transactional safety.