Chapter 9. Extending SQL: Functions

Table of Contents
9.1. Introduction
9.2. Query Language (SQL) Functions
9.2.1. Examples
9.2.2. SQL Functions on Base Types
9.2.3. SQL Functions on Composite Types
9.2.4. SQL Table Functions
9.2.5. SQL Functions Returning Sets
9.3. Procedural Language Functions
9.4. Internal Functions
9.5. C Language Functions
9.5.1. Dynamic Loading
9.5.2. Base Types in C-Language Functions
9.5.3. Version-0 Calling Conventions for C-Language Functions
9.5.4. Version-1 Calling Conventions for C-Language Functions
9.5.5. Composite Types in C-Language Functions
9.5.6. Table Function API
9.5.7. Writing Code
9.5.8. Compiling and Linking Dynamically-Loaded Functions
9.6. Function Overloading
9.7. Table Functions
9.8. Procedural Language Handlers

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