A stored procedure in AnalyticDB for PostgreSQL encapsulates a set of SQL statements that are compiled and stored permanently. To call a stored procedure, specify its name and parameters.
AnalyticDB for PostgreSQL supports stored procedures written in PL/pgSQL, a procedural language that ships with the database.
PL/pgSQL - SQL procedural language
PL/pgSQL is an easy-to-use, loadable procedural language that ships with AnalyticDB for PostgreSQL. It extends SQL with programming constructs so you can build complex logic in the database.
PL/pgSQL supports the following capabilities:
Functions and trigger procedures — create reusable functions and event-driven trigger logic
Control structures — use conditional expressions, loops, and branching within SQL procedures
Complex computing — perform multi-step calculations beyond what a single SQL statement supports
User-defined types, functions, and operators — extend the type system and query language to fit your data model
Server-trusted execution — procedures run with server-level trust
Functions written in PL/pgSQL work in the same contexts as built-in AnalyticDB for PostgreSQL functions. For example, complex conditional expressions can define custom operators and index functions.