Databases and storage · Concept

Triggers and database functions

Code that runs inside the database, either automatically when rows change (a trigger) or when an app calls it by name (a function).

Keeping data correct · updated

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.

More in Databases and storage

Keeping data correct

All 25 Databases and storage terms

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.