PL/pgSQL is an imperative SQL-like language that offers several features to write a piece of runnable code. Besides SQL, this is the default language used in PostgreSQL to write functions, procedures, triggers, and programs in general.
PostgreSQL has a special statement called DO that accepts a PL/pgSQL piece of code and executes it as an anonymous code block. This is particularly handy to learn features of the language or to execute a code snippet without having to wrap it into a function or a routine. The syntax of the DO statement is quite straightforward and only requires us to specify the block of code to execute:
DO <plpgsql code block>;
In the rest of the chapter, the DO statement will be used to run PL/pgSQL pieces of code and demonstrate all the main features of the language.
A runnable PL/pgSQL piece of code must contain at least one...