postgresql-plpgsql

Write PL/pgSQL - functions, procedures, triggers, error handling

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "postgresql-plpgsql" with this command: npx skills add pluginagentmarketplace/custom-plugin-postgresql/pluginagentmarketplace-custom-plugin-postgresql-postgresql-plpgsql

PostgreSQL PL/pgSQL Skill

Atomic skill for procedural programming

Overview

Production-ready patterns for functions, procedures, triggers, and exception handling.

Prerequisites

  • PostgreSQL 16+
  • Understanding of SQL

Parameters

parameters:
  code_type:
    type: string
    required: true
    enum: [function, procedure, trigger, aggregate]
  volatility:
    type: string
    enum: [IMMUTABLE, STABLE, VOLATILE]

Quick Reference

Function Template

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; $$;

Trigger Template

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();

Volatility

CategoryUse Case
IMMUTABLEMath, formatting
STABLELookups (no writes)
VOLATILEINSERT, random()

Exception Handling

EXCEPTION
    WHEN unique_violation THEN ...  -- 23505
    WHEN foreign_key_violation THEN ...  -- 23503
    WHEN OTHERS THEN RAISE EXCEPTION '% [%]', SQLERRM, SQLSTATE;

Troubleshooting

ErrorCauseSolution
42883Function not foundCheck signature
42P13Invalid definitionReview syntax
Trigger not firingWrong timingCheck BEFORE/AFTER

Usage

Skill("postgresql-plpgsql")

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

postgresql-advanced-queries

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

postgresql-fundamentals

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

postgresql-performance

No summary provided by upstream source.

Repository SourceNeeds Review