# DB

> Database (PostgreSQL) SQL best practices for clean, performant, and maintainable queries. Use when writing or reviewing SQL, schema changes, or database-related guidance. Use when this capability is needed.

- Skill: `tomevault-io/db-4` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/db-4`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/db-4/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Data & Analytics
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/db-4

---


# Database Stack Skill

## Default guidance

Use the PostgreSQL rule file in this folder as the authoritative reference.

## Workflow (use this order)

1. Confirm schema context and target tables/columns.
2. Draft query with explicit columns and clear aliases.
3. Prefer CTEs for readability and reuse.
4. Avoid `NOT IN`; use `NOT EXISTS` or `LEFT JOIN ... IS NULL`.
5. Run `explain analyze` and address sequential scans.
6. Add or adjust indexes if query plan needs them.

## Review Checklist

- Naming uses `snake_case`; SQL keywords are lowercase.
- Explicit joins used; no implicit joins.
- `select *` avoided; columns are explicit.
- `NOT IN` avoided with `NULL`-safe alternatives.
- Query plan checked with `explain analyze`.

## Local Resources

- `postgresql.mdc` for naming, formatting, query patterns, and performance guidance.

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/heyayushh) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

