What is Stored Procedure?
A precompiled collection of SQL statements stored in the database that can be executed as a single unit.
Stored procedures encapsulate complex database logic on the server side. They accept parameters, perform operations, and return results. Benefits include reduced network traffic, code reuse, and centralized business logic.
In PostgreSQL, functions (CREATE FUNCTION) serve a similar purpose, supporting PL/pgSQL, PL/Python, and other languages. Modern development often favors application-level logic, but stored procedures remain valuable for complex data operations.