Write PL/pgSQL - functions, procedures, triggers, error handling
Writes PL/pgSQL functions, procedures, triggers, and exception handling blocks. Triggers when you need procedural logic, custom database functions, or automated trigger-based actions in PostgreSQL.
/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 procedural programming
Production-ready patterns for functions, procedures, triggers, and exception handling.
parameters:
code_type:
type: string
required: true
enum: [function, procedure, trigger, aggregate]
volatility:
type: string
enum: [IMMUTABLE, STABLE, VOLATILE]
CREATE OR REPLACE FUNCTION func_name(p_param TYPE)
RETURNS return_type
LANGUAGE plpgsql STABLE SECURITY DEFINER
SET search_path = app, public
AS $$ DECLARE v_result TYPE; BEGIN
-- Logic
RETURN v_result;
EXCEPTION WHEN OTHERS THEN
RAISE WARNING '%', SQLERRM;
RETURN NULL;
END; $$;
CREATE OR REPLACE FUNCTION trigger_func() RETURNS TRIGGER AS $$
BEGIN
IF TG_OP = 'UPDATE' THEN NEW.updated_at := NOW(); END IF;
RETURN NEW;
END; $$ LANGUAGE plpgsql;
CREATE TRIGGER trg_name BEFORE UPDATE ON t FOR EACH ROW EXECUTE FUNCTION trigger_func();
| Category | Use Case |
|---|---|
| IMMUTABLE | Math, formatting |
| STABLE | Lookups (no writes) |
| VOLATILE | INSERT, random() |
EXCEPTION
WHEN unique_violation THEN ... -- 23505
WHEN foreign_key_violation THEN ... -- 23503
WHEN OTHERS THEN RAISE EXCEPTION '% [%]', SQLERRM, SQLSTATE;
| Error | Cause | Solution |
|---|---|---|
42883 | Function not found | Check signature |
42P13 | Invalid definition | Review syntax |
| Trigger not firing | Wrong timing | Check BEFORE/AFTER |
Skill("postgresql-plpgsql")
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.
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.