Chapter 37. PL/pgSQL - SQL Procedural Language

Table of Contents
37.1. Overview
37.1.1. Advantages of Using PL/pgSQL
37.1.2. Supported Argument and Result Data Types
37.2. Tips for Developing in PL/pgSQL
37.3. Structure of PL/pgSQL
37.4. Declarations
37.4.1. Aliases for Function Parameters
37.4.2. Copying Types
37.4.3. Row Types
37.4.4. Record Types
37.4.5. RENAME
37.5. Expressions
37.6. Basic Statements
37.6.1. Assignment
37.6.2. Executing a Query With No Result
37.6.3. Executing a Query with a Single-Row Result
37.6.4. Doing Nothing At All
37.6.5. Executing Dynamic Commands
37.6.6. Obtaining the Result Status
37.7. Control Structures
37.7.1. Returning From a Function
37.7.2. Conditionals
37.7.3. Simple Loops
37.7.4. Looping Through Query Results
37.7.5. Trapping Errors
37.8. Cursors
37.8.1. Declaring Cursor Variables
37.8.2. Opening Cursors
37.8.3. Using Cursors
37.9. Errors and Messages
37.10. Trigger Procedures
37.11. Porting from Oracle PL/SQL
37.11.1. Porting Examples
37.11.2. Other Things to Watch For
37.11.3. Appendix

PL/pgSQL is a loadable procedural language for the PostgreSQL database system. The design goals of PL/pgSQL were to create a loadable procedural language that

Except for input/output conversion and calculation functions for user-defined types, anything that can be defined in C language functions can also be done with PL/pgSQL. For example, it is possible to create complex conditional computation functions and later use them to define operators or use them in index expressions.