Stored Procedures & CALL
Multi-step logic inside the database. Production-oriented PostgreSQL guidance.
Search across all documentation pages
Multi-step logic inside the database. Production-oriented PostgreSQL guidance.
CREATE OR REPLACE PROCEDURE app.transfer_credit(p_from bigint, p_to bigint, p_amount numeric)
LANGUAGE plpgsql AS $$
BEGIN
UPDATE app.wallets SET balance = balance - p_amount WHERE account_id = p_from;
UPDATE app.wallets SET balance = balance + p_amount WHERE account_id = p_to;
END;
$$;When to reach for this: You implement or review SQL using this concept in PostgreSQL 18.
CALL app.transfer_credit(1, 2, 10.00);What this demonstrates:
| Alternative | Use When | Don't Use When |
|---|---|---|
| Application-level logic | Simple CRUD | Integrity spread across services |
| Materialized view | Heavy repeated reads | Refresh complexity |
| External stream processor | Cross-system events | Extra operational surface |
Read-only replicas execute SELECT; writes go to primary.
Transaction pooling affects session-level features; use session mode when needed.
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, PgBouncer 1.x, Patroni 3.x, and PostGIS 3.5+.
Reviewed by Chris St. John·Last updated Jul 19, 2026