db

Optimize PostgreSQL SQL queries for readability, performance, and maintainability.

3|1|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/heyAyushh/stacc --skill db-heyayushh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: db
Source: https://github.com/heyAyushh/stacc/tree/main/configs/stacks/databases
Command: npx skills add https://github.com/heyAyushh/stacc --skill db-heyayushh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

PostgreSQL query writing and review can drift into hard-to-maintain, slow, and error-prone SQL. This Skill provides guidelines to keep queries readable, efficient, and safe across schemas and changes.

Core Features & Use Cases

  • Enforces explicit column lists and clear aliases to improve readability and maintainability.
  • Promotes the use of CTEs for readability, reuse, and safe composition of complex queries.
  • Guides performance tuning with explain analyze checks and indexing considerations during reviews.
  • Useful for authoring new queries, reviewing existing ones, and validating schema migrations or refactors.

Quick Start

Use the db skill to audit a sample SQL query and rewrite it to use explicit columns, proper joins, and a validated EXPLAIN ANALYZE plan.

Frequently Asked Questions about db

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

FAQPage Schema
How do I optimize PostgreSQL queries for better performance and readability?

You optimize PostgreSQL queries by enforcing explicit column lists, using CTEs for complex logic, avoiding NOT IN clauses, and validating execution plans with EXPLAIN ANALYZE to ensure maintainability and speed.

What is the best way to review SQL queries during a PostgreSQL code review?

Reviewing SQL queries involves checking for explicit column lists, clear aliases, and beneficial CTE usage, then validating performance with EXPLAIN ANALYZE and indexing considerations to catch slow or error-prone logic.

When should I use CTEs in PostgreSQL instead of subqueries?

Use CTEs in PostgreSQL when you need to improve query readability, enable safe composition of complex logic, or reuse intermediate result sets, avoiding nested subqueries that drift into hard-to-maintain SQL.

Why should I avoid NOT IN clauses in my SQL query optimization?

You avoid NOT IN clauses because they can produce error-prone results with NULL values, making queries hard to maintain; using alternative joins or NOT EXISTS constructs keeps PostgreSQL queries clean and safe.

Can I validate schema migrations using EXPLAIN ANALYZE in PostgreSQL?

Yes, you validate schema migrations or refactors by running EXPLAIN ANALYZE on affected PostgreSQL queries to check execution plans, confirm performance tuning, and ensure safe changes across development and production environments.

Does writing explicit column lists instead of SELECT * improve PostgreSQL query maintainability?

Writing explicit column lists improves PostgreSQL query maintainability by preventing unexpected schema drift, ensuring clear aliases, and keeping query results predictable across schema migrations and production environments.