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 ];
Let's see what the keywords mean:
name
: The name should follow the naming rules discussed in Chapter 3, 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
: The type of variable can be simple such as integer, user defined data type, pseudo type, record, and so on. Since a type is created implicitly on creating a table, one can use this type to declare a variable.Tip
In PostgreSQL, the following two declarations are equivalent; however...