The PostgreSQL PL/pgSQL control statements
The PostgreSQL control structure is an essential part of the PL/pgSQL language; it enables developers to code very complex business logic inside PostgreSQL.
Declaration statements
The general syntax of a variable declaration is as follows:
name [ CONSTANT ] type [ COLLATE collation_name ] [ NOT NULL ] [ { DEFAULT | := | = } expression ];
name
: The name should follow the naming rules discussed in Chapter 03, PostgreSQL Basic Building Blocks. For example, the name should not start with an integer.CONSTANT
: The variable cannot be assigned another value after the initialization. This is useful in defining constant variables such as PI.type
: Thetype
of variable can be simple, such as an integer, user-defined data type, pseudo type, record, and so on. Since a type is created implicitly when creating a table, one can use thistype
to declare a variable.
Note
In PostgreSQL, the following two declarations are equivalent; however, the second declaration is more...