Master advanced PostgreSQL queries - CTEs, window functions, recursive queries
Generates complex PostgreSQL queries including CTEs, window functions, recursive queries, and lateral joins. Use when asked for advanced SQL patterns or multi-step data analysis.
/plugin marketplace add pluginagentmarketplace/custom-plugin-postgresql/plugin install ultrathink@pluginagentmarketplace-postgresqlThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyAtomic skill for complex query patterns
Production-ready patterns for CTEs, window functions, recursive queries, and advanced joins.
parameters:
query_type:
type: string
required: true
enum: [cte, window, recursive, lateral, aggregate]
tables:
type: array
items: { type: string }
WITH step1 AS (SELECT ...), step2 AS (SELECT ... FROM step1)
SELECT * FROM step2;
ROW_NUMBER() OVER (PARTITION BY cat ORDER BY date DESC)
SUM(amount) OVER (ORDER BY date) -- Running total
LAG(value, 1) OVER (ORDER BY date) -- Previous row
WITH RECURSIVE tree AS (
SELECT id, parent_id, 1 as level FROM items WHERE parent_id IS NULL
UNION ALL
SELECT i.id, i.parent_id, t.level + 1 FROM items i JOIN tree t ON i.parent_id = t.id
)
SELECT * FROM tree;
SELECT u.*, r.* FROM users u
CROSS JOIN LATERAL (SELECT * FROM orders WHERE user_id = u.id LIMIT 3) r;
DO $$ DECLARE result NUMERIC; BEGIN
CREATE TEMP TABLE test_sales (id INT, amount NUMERIC);
INSERT INTO test_sales VALUES (1, 100), (2, 200);
SELECT SUM(amount) OVER (ORDER BY id) INTO result FROM test_sales WHERE id = 2;
ASSERT result = 300, 'Running total should be 300';
DROP TABLE test_sales;
END $$;
| Error | Cause | Solution |
|---|---|---|
42803 | GROUP BY error | Add missing columns |
54001 | Too complex | Break into CTEs |
21000 | Multiple rows | Add LIMIT 1 |
Skill("postgresql-advanced-queries")
Use when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.