September 26, 2024: PostgreSQL 17 Released!
Supported Versions: Current (17) / 16 / 15 / 14 / 13 / 12
Development Versions: devel
Unsupported versions: 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

Chapter 33. Extending SQL

Table of Contents
33.1. How Extensibility Works
33.2. The PostgreSQL Type System
33.2.1. Base Types
33.2.2. Composite Types
33.2.3. Domains
33.2.4. Pseudo-Types
33.2.5. Polymorphic Types
33.3. User-Defined Functions
33.4. Query Language (SQL) Functions
33.4.1. SQL Functions on Base Types
33.4.2. SQL Functions on Composite Types
33.4.3. Functions with Output Parameters
33.4.4. SQL Functions as Table Sources
33.4.5. SQL Functions Returning Sets
33.4.6. Polymorphic SQL Functions
33.5. Function Overloading
33.6. Function Volatility Categories
33.7. Procedural Language Functions
33.8. Internal Functions
33.9. C-Language Functions
33.9.1. Dynamic Loading
33.9.2. Base Types in C-Language Functions
33.9.3. Version 0 Calling Conventions
33.9.4. Version 1 Calling Conventions
33.9.5. Writing Code
33.9.6. Compiling and Linking Dynamically-Loaded Functions
33.9.7. Extension Building Infrastructure
33.9.8. Composite-Type Arguments
33.9.9. Returning Rows (Composite Types)
33.9.10. Returning Sets
33.9.11. Polymorphic Arguments and Return Types
33.9.12. Shared Memory and LWLocks
33.10. User-Defined Aggregates
33.11. User-Defined Types
33.12. User-Defined Operators
33.13. Operator Optimization Information
33.13.1. COMMUTATOR
33.13.2. NEGATOR
33.13.3. RESTRICT
33.13.4. JOIN
33.13.5. HASHES
33.13.6. MERGES (SORT1, SORT2, LTCMP, GTCMP)
33.14. Interfacing Extensions To Indexes
33.14.1. Index Methods and Operator Classes
33.14.2. Index Method Strategies
33.14.3. Index Method Support Routines
33.14.4. An Example
33.14.5. Cross-Data-Type Operator Classes
33.14.6. System Dependencies on Operator Classes
33.14.7. Special Features of Operator Classes

In the sections that follow, we will discuss how you can extend the PostgreSQL SQL query language by adding: