How it works
A trigger can stamp updated_at on every edit, write an audit row, or create follow-up records when an order arrives. A database function bundles several steps, such as checking and reducing stock, into one call that runs as a single transaction, which avoids race conditions between two buyers.
In PostgreSQL these are usually written in SQL or PL/pgSQL, and Supabase exposes functions to apps as RPC calls. Logic that lives in the database is powerful but easy to forget, so it belongs in migrations and deserves documentation.
Related terms
More in Databases and storage
Keeping data correct