Use when writing advanced PostgreSQL queries.
Scanned 9/10/2026
Install to Claude Code
npx -y skills add LoopyLuci/Skills --skill postgresql-advanced-queries --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Postgresql Advanced Queries?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/loopyluci-postgresql-advanced-queries)More formats (shields.io, HTML) on the badges page.
---
name: postgresql-advanced-queries
description: "Use when writing advanced PostgreSQL queries."
version: 1.0.0
author: Hermes Agent
license: MIT
metadata:
hermes:
tags: [postgresql, SQL, CTEs, window-functions, jsonb, full-text-search]
related_skills: [sql-advanced-patterns, database-design-patterns, data-modeling-foundations]
---
# Advanced PostgreSQL Queries
Writing advanced PostgreSQL queries — from CTEs and window functions through JSONB, full-text search, recursive queries, and performance tuning.
## When to Use
- Writing complex analytical SQL queries
- Using PostgreSQL-specific features (JSONB, GIN indexes)
- Full-text search with tsvector
- Recursive CTEs for tree/graph data
- Query optimization with EXPLAIN ANALYZE
## PostgreSQL Patterns
```sql
-- Recursive CTE for tree traversal
WITH RECURSIVE org_tree AS (
SELECT id, name, manager_id, 1 AS depth
FROM employees WHERE manager_id IS NULL
UNION ALL
SELECT e.id, e.name, e.manager_id, ot.depth + 1
FROM employees e INNER JOIN org_tree ot ON e.manager_id = ot.id
)
SELECT * FROM org_tree ORDER BY depth, name;
-- Full-text search
SELECT title, ts_rank(to_tsvector('english', body), plainto_tsquery('search terms')) AS rank
FROM articles
WHERE to_tsvector('english', body) @@ plainto_tsquery('search terms')
ORDER BY rank DESC;
-- JSONB queries
SELECT data->>'name' AS name, data->>'email' AS email
FROM users WHERE data @> '{"role": "admin"}'::jsonb;
```
## Verification Checklist
- [ ] Recursive CTE has termination condition
- [ ] Window functions (ROW_NUMBER, LAG, LEAD) correct
- [ ] GIN indexes for JSONB and full-text search
- [ ] EXPLAIN ANALYZE for query performance
- [ ] Partial indexes for filtered queries
- [ ] Materialized views for expensive queries
- [ ] Table partitioning for large tables
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!