cadasto/pgsql-coding-plugin/pgsql-schema
Claude Code and agent skill by cadasto/pgsql-coding-plugin
- community
Checking that the SKILL.md file is still in the repository.
This skill should be used when a task designs or reviews PostgreSQL tables and the objects around them, for example "design these tables", "which type for money or ids", "should status be an enum", "cascade the delete", "add row-level security per tenant". Covers CREATE TABLE, column types (identity or serial, uuid or uuidv7, text or varchar, timestamptz, numeric for money, enum, domain, array, range or multirange), constraints (NOT NULL, CHECK, UNIQUE NULLS NOT DISTINCT, PRIMARY KEY, FOREIGN K…
Install
npx vskill@latest install cadasto/pgsql-coding-plugin/pgsql-schemaSKILL.md
The same SKILL.md was published earlier as cadasto/pgsql-coding-plugin/pgsql-schema.
pgsql-schema: tables, types, constraints and database objects
Scope: what a CREATE TABLE, CREATE FUNCTION, CREATE TRIGGER, CREATE POLICY or GRANT should say on PostgreSQL 18.
Deterministic backstop: squawk on migration files flags serial (prefer-identity), int keys (prefer-bigint-over-int), varchar(n) (prefer-text-field), timestamp (prefer-timestamptz) and char(n) (ban-char-field). SELECT * FROM plpgsql_check_function('fn(int)', security_warnings => true) from the plpgsql_check extension checks each PL/pgSQL function. Name the tool when it would catch the slip; the rules below are the ones that pass both.
Rules
- Keys are `bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY`, never `serial`. The serial types are "not true types" (numeric types) and the wiki says to use identity columns (Don't Do This). An identity column is NOT NULL but not unique, so it still needs the PRIMARY KEY (identity columns).
- Use `uuidv7()` when a key is minted outside the database or merged across databases. It is time-ordered, unlike
gen_random_uuid(), and anyone holding it can read its creation time withuuid_extract_timestamp()(UUID functions). Store it asuuid, a 128-bit value, never astext(UUID type). - `text` with a CHECK, not `varchar(n)` or `char(n)`. The three perform the same, and
char(n)pads with spaces and is usually the slowest (character types). Put the real limit in a CHECK (Don't Do This). - `timestamptz` for a moment in time. It is stored as UTC and shown in the session
TimeZone;timetzis not recommended (date/time types). Plaintimestampis a wall-clock reading, not a moment (Don't Do This). - `numeric` for money and any exact quantity. Floating-point types store approximations (numeric types);
moneydepends onlc_monetaryand stores no currency (Don't Do This). Keep the currency in its own column. - NOT NULL unless null means something. "In most database designs the majority of columns should be marked not null" (constraints).
- Lowercase snake_case names, never quoted. Unquoted names fold to lower case, quoted ones become case-sensitive, and a name past 63 bytes is truncated (lexical structure). Name constraints and indexes explicitly.
- Every foreign key states its ON DELETE action. The default, NO ACTION, usually makes the delete fail (constraints). The index its referencing columns need is
pgsql-indexing. - Cross-row rules go in UNIQUE, EXCLUDE or FOREIGN KEY, never in a CHECK. A CHECK is assumed immutable and sees only its own row; one that reads other rows lets bad data in and can break a dump restore (constraints).
- Non-overlapping periods use `WITHOUT OVERLAPS` or `EXCLUDE USING gist`. PostgreSQL 18 adds temporal
PRIMARY KEYandUNIQUE ... WITHOUT OVERLAPSandFOREIGN KEY ... PERIOD; scalar columns beside the range needbtree_gist(CREATE TABLE). - Say `STORED` or `VIRTUAL` on every generated column. VIRTUAL is the PostgreSQL 18 default (generated columns). A virtual column cannot be indexed or carry a primary key or unique constraint (indexcmds.c) and never has statistics (ALTER TABLE), so make it STORED when queries filter on it or it needs an index, as with a value extracted from jsonb.
- Label function volatility honestly. VOLATILE is the default, a function that depends on
TimeZoneis STABLE, and a false IMMUTABLE can fold a stale value into a cached plan (volatility). - Pin `search_path` on SECURITY DEFINER and keep input out of SQL text. Write
SET search_path = trusted_schema, pg_tempand revoke EXECUTE from PUBLIC in the same transaction (CREATE FUNCTION). In PL/pgSQL, pass identifiers throughformat('%I', ...)and values throughEXECUTE ... USING(PL/pgSQL statements). - Row-level security does not bind the table owner. Connect the application as a role that does not own the tables, or add FORCE ROW LEVEL SECURITY (row security). A view over such a table applies its owner's policies unless created
WITH (security_invoker = true)(CREATE VIEW). - Partition only a table that outgrows memory, on the column most queries filter by. Every PRIMARY KEY and UNIQUE constraint must include the partition key (partitioning).
Changing an existing table without blocking writers is pgsql-migrations. The shape and indexing of a jsonb column is pgsql-jsonb.
Read the reference
| The task involves | Read | |
|---|---|---|
| a key, a UUID, a string, a time, money, an enum, a domain, an array, a range, a generated column | types.md | |
| NOT NULL, CHECK, UNIQUE, a foreign key and its ON DELETE, DEFERRABLE, EXCLUDE, WITHOUT OVERLAPS, PERIOD, NOT ENFORCED, constraint names | constraints.md | |
| CREATE FUNCTION or PROCEDURE, PL/pgSQL, volatility, STRICT, PARALLEL, dynamic SQL, a trigger | functions.md | |
| roles, GRANT, the public schema, search_path, SECURITY DEFINER, row-level security, a view's privileges | security.md | |
| PARTITION BY, a default partition, pruning, detaching a partition | partitioning.md |
Sources
- PostgreSQL 18 manual: data types, constraints, CREATE TABLE, generated columns, partitioning, CREATE FUNCTION, row security (checked 2026-10-27)
- PostgreSQL 18 release notes: <https://www.postgresql.org/docs/18/release-18.html> (checked 2026-10-27)
- PostgreSQL wiki, Don't Do This: <https://wiki.postgresql.org/wiki/Don%27t_Do_This> (checked 2026-10-27)
- PostgreSQL source,
indexcmds.conREL_18_STABLE: <https://github.com/postgres/postgres/blob/REL_18_STABLE/src/backend/commands/indexcmds.c> (checked 2026-10-27) - Squawk rules: <https://squawkhq.com/docs/rules>; plpgsql_check: <https://github.com/okbob/plpgsql_check> (checked 2026-10-27)
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/pgsql-schema/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cadasto/pgsql-coding-plugin/pgsql-schema)