Skip to content
Back to skills

Writing Sql Postgresql

ASecurity

Use when writing or editing PostgreSQL 15+ queries, schemas, or migrations. Triggers on `.sql` files, migration files, CTEs, indexes, JSONB, row-level security, EXPLAIN ANALYZE, or constraints, even when the user doesn't say 'Postgres'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsgosqldatabasesecurityperformance

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill writing-sql-postgresql --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing Sql Postgresql?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Writing Sql Postgresql
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-writing-sql-postgresql/badge)](https://www.skillsdirectory.com/skills/xonovex-writing-sql-postgresql)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: writing-sql-postgresql
description: "Use when writing or editing PostgreSQL 15+ queries, schemas, or migrations. Triggers on `.sql` files, migration files, CTEs, indexes, JSONB, row-level security, EXPLAIN ANALYZE, or constraints, even when the user doesn't say 'Postgres'."
---

# PostgreSQL Coding Guidelines

Write PostgreSQL queries and schemas with explicit constraints, transactional changes, and measured query plans.

## Requirements

- PostgreSQL ≥ 15.

## Essentials

- **Query composition** - Use CTEs to decompose complex queries, name descriptively, see [references/cte-patterns.md](references/cte-patterns.md)
- **Schema design** - Choose precise types, index for access paths, avoid over-indexing, see [references/data-types.md](references/data-types.md), [references/indexing.md](references/indexing.md)
- **Data integrity** - Enforce with PK/FK/UNIQUE/CHECK/NOT NULL constraints, see [references/constraints.md](references/constraints.md)
- **Semi-structured data** - Use JSONB with GIN indexes, see [references/jsonb.md](references/jsonb.md)
- **Multi-tenancy** - Apply RLS and role-based access for data isolation, see [references/row-level-security.md](references/row-level-security.md), [references/role-based-access.md](references/role-based-access.md)
- **Performance** - Analyze query plans and tune, see [references/performance.md](references/performance.md)

## Gotchas

- `ANALYZE` updates planner statistics: bulk inserts without re-analyzing produce stale plans and full scans
- `JSONB` supports indexing (GIN); `JSON` doesn't: pick JSONB unless you specifically need preserved formatting
- Most DDL participates in transactions, but commands such as `CREATE INDEX CONCURRENTLY` cannot run inside a transaction block: check every migration operation before wrapping the whole file
- Prefer SQL-standard `GENERATED ... AS IDENTITY` for new auto-generated keys because its sequence relationship and override rules are declared on the column; `SERIAL`/`BIGSERIAL` remain supported PostgreSQL shorthand, not deprecated syntax

## Progressive disclosure

- Read [references/cte-patterns.md](references/cte-patterns.md) - Load when breaking down complex queries or improving readability
- Read [references/data-types.md](references/data-types.md) - Load when choosing column types or avoiding type mismatches
- Read [references/indexing.md](references/indexing.md) - Load when optimizing slow queries or query planning
- Read [references/constraints.md](references/constraints.md) - Load when enforcing data integrity rules
- Read [references/jsonb.md](references/jsonb.md) - Load when storing semi-structured or dynamic data
- Read [references/row-level-security.md](references/row-level-security.md) - Load when implementing multi-tenant data isolation
- Read [references/role-based-access.md](references/role-based-access.md) - Load when configuring database user permissions
- Read [references/performance.md](references/performance.md) - Load when analyzing query plans or tuning performance

Files in this skill

  • SKILL.md3 KB
  • eval-output.json4.1 KB
  • eval-trigger.json6 KB
  • moon.yml86 B
  • references/constraints.md633 B
  • references/cte-patterns.md592 B
  • references/data-types.md848 B
  • references/indexing.md744 B
  • references/jsonb.md705 B
  • references/performance.md388 B
  • references/role-based-access.md763 B
  • references/row-level-security.md930 B
  • sources.json1.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.