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 ...

Get Learning PostgreSQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.