Chapter 11. Extending SQL: Functions

Table of Contents
11.1. Introduction
11.2. Query Language (SQL) Functions
11.2.1. Examples
11.2.2. SQL Functions on Base Types
11.2.3. SQL Functions on Composite Types
11.2.4. SQL Table Functions
11.2.5. SQL Functions Returning Sets
11.3. Procedural Language Functions
11.4. Internal Functions
11.5. C Language Functions
11.5.1. Dynamic Loading
11.5.2. Base Types in C-Language Functions
11.5.3. Version-0 Calling Conventions for C-Language Functions
11.5.4. Version-1 Calling Conventions for C-Language Functions
11.5.5. Composite Types in C-Language Functions
11.5.6. Table Function API
11.5.7. Writing Code
11.5.8. Compiling and Linking Dynamically-Loaded Functions
11.6. Function Overloading
11.7. Table Functions
11.8. Procedural Language Handlers

11.1. Introduction

PostgreSQL provides four kinds of functions:

Every kind of function can take a base type, a composite type, or some combination as arguments (parameters). In addition, every kind of function can return a base type or a composite type. It's easiest to define SQL functions, so we'll start with those. Examples in this section can also be found in funcs.sql and funcs.c in the tutorial directory.

Throughout this chapter, it can be useful to look at the reference page of the CREATE FUNCTION command to understand the examples better.