Skip to main content
The DO statement defines a code block that executes PL/pgSQL syntax.

Required privileges

  • To define a DO block with a user-defined type, a user must have USAGE privilege on the user-defined type.

Synopsis

do syntax diagram

Parameters

Examples

Declare a variable in a DO block

The following example uses the PL/pgSQL DECLARE syntax to declare variables to use in the code block.

Use a loop in a DO block

The following example uses the PL/pgSQL WHILE syntax to loop through several statements.

Use a common table expression in a DO block

The following example uses a common table expression in the body of the code block.

See also