--- title: "Extending SQL" id: extend pg_version: "20devel" --- # Extending SQL ## Table of Contents - [36.1. How Extensibility Works](extend-how.md) - [36.2. The PostgreSQL Type System](extend-type-system.md) - [36.2.1. Base Types](extend-type-system.md#extend-type-system-base) - [36.2.2. Container Types](extend-type-system.md#extend-type-system-container) - [36.2.3. Domains](extend-type-system.md#extend-type-system-domains) - [36.2.4. Pseudo-Types](extend-type-system.md#extend-type-system-pseudo) - [36.2.5. Polymorphic Types](extend-type-system.md#extend-types-polymorphic) - [36.3. User-Defined Functions](xfunc.md) - [36.4. User-Defined Procedures](xproc.md) - [36.5. Query Language (SQL) Functions](xfunc-sql.md) - [36.5.1. Arguments for SQL Functions](xfunc-sql.md#xfunc-sql-function-arguments) - [36.5.2. SQL Functions on Base Types](xfunc-sql.md#xfunc-sql-base-functions) - [36.5.3. SQL Functions on Composite Types](xfunc-sql.md#xfunc-sql-composite-functions) - [36.5.4. SQL Functions with Output Parameters](xfunc-sql.md#xfunc-output-parameters) - [36.5.5. SQL Procedures with Output Parameters](xfunc-sql.md#xfunc-output-parameters-proc) - [36.5.6. SQL Functions with Variable Numbers of Arguments](xfunc-sql.md#xfunc-sql-variadic-functions) - [36.5.7. SQL Functions with Default Values for Arguments](xfunc-sql.md#xfunc-sql-parameter-defaults) - [36.5.8. SQL Functions as Table Sources](xfunc-sql.md#xfunc-sql-table-functions) - [36.5.9. SQL Functions Returning Sets](xfunc-sql.md#xfunc-sql-functions-returning-set) - [36.5.10. SQL Functions Returning `TABLE`](xfunc-sql.md#xfunc-sql-functions-returning-table) - [36.5.11. Polymorphic SQL Functions](xfunc-sql.md#xfunc-sql-polymorphic-functions) - [36.5.12. SQL Functions with Collations](xfunc-sql.md#xfunc-sql-collations) - [36.6. Function Overloading](xfunc-overload.md) - [36.7. Function Volatility Categories](xfunc-volatility.md) - [36.8. Procedural Language Functions](xfunc-pl.md) - [36.9. Internal Functions](xfunc-internal.md) - [36.10. C-Language Functions](xfunc-c.md) - [36.10.1. Dynamic Loading](xfunc-c.md#xfunc-c-dynload) - [36.10.2. Base Types in C-Language Functions](xfunc-c.md#xfunc-c-basetype) - [36.10.3. Version 1 Calling Conventions](xfunc-c.md#xfunc-c-v1-call-conv) - [36.10.4. Writing Code](xfunc-c.md#xfunc-c-code) - [36.10.5. Compiling and Linking Dynamically-Loaded Functions](xfunc-c.md#dfunc) - [36.10.6. Server API and ABI Stability Guidance](xfunc-c.md#xfunc-api-abi-stability-guidance) - [36.10.7. Composite-Type Arguments](xfunc-c.md#xfunc-c-composite-type-args) - [36.10.8. Returning Rows (Composite Types)](xfunc-c.md#xfunc-c-returning-rows) - [36.10.9. Returning Sets](xfunc-c.md#xfunc-c-return-set) - [36.10.10. Polymorphic Arguments and Return Types](xfunc-c.md#xfunc-c-polymorphic) - [36.10.11. Shared Memory](xfunc-c.md#xfunc-shared-addin) - [36.10.12. LWLocks](xfunc-c.md#xfunc-addin-lwlocks) - [36.10.13. Custom Wait Events](xfunc-c.md#xfunc-addin-wait-events) - [36.10.14. Injection Points](xfunc-c.md#xfunc-addin-injection-points) - [36.10.15. Custom Cumulative Statistics](xfunc-c.md#xfunc-addin-custom-cumulative-statistics) - [36.10.16. Using C++ for Extensibility](xfunc-c.md#extend-cpp) - [36.11. Function Optimization Information](xfunc-optimization.md) - [36.12. User-Defined Aggregates](xaggr.md) - [36.12.1. Moving-Aggregate Mode](xaggr.md#xaggr-moving-aggregates) - [36.12.2. Polymorphic and Variadic Aggregates](xaggr.md#xaggr-polymorphic-aggregates) - [36.12.3. Ordered-Set Aggregates](xaggr.md#xaggr-ordered-set-aggregates) - [36.12.4. Partial Aggregation](xaggr.md#xaggr-partial-aggregates) - [36.12.5. Support Functions for Aggregates](xaggr.md#xaggr-support-functions) - [36.13. User-Defined Types](xtypes.md) - [36.13.1. TOAST Considerations](xtypes.md#xtypes-toast) - [36.14. User-Defined Operators](xoper.md) - [36.15. Operator Optimization Information](xoper-optimization.md) - [36.15.1. `COMMUTATOR`](xoper-optimization.md#xoper-commutator) - [36.15.2. `NEGATOR`](xoper-optimization.md#xoper-negator) - [36.15.3. `RESTRICT`](xoper-optimization.md#xoper-restrict) - [36.15.4. `JOIN`](xoper-optimization.md#xoper-join) - [36.15.5. `HASHES`](xoper-optimization.md#xoper-hashes) - [36.15.6. `MERGES`](xoper-optimization.md#xoper-merges) - [36.16. Interfacing Extensions to Indexes](xindex.md) - [36.16.1. Index Methods and Operator Classes](xindex.md#xindex-opclass) - [36.16.2. Index Method Strategies](xindex.md#xindex-strategies) - [36.16.3. Index Method Support Routines](xindex.md#xindex-support) - [36.16.4. An Example](xindex.md#xindex-example) - [36.16.5. Operator Classes and Operator Families](xindex.md#xindex-opfamily) - [36.16.6. System Dependencies on Operator Classes](xindex.md#xindex-opclass-dependencies) - [36.16.7. Ordering Operators](xindex.md#xindex-ordering-ops) - [36.16.8. Special Features of Operator Classes](xindex.md#xindex-opclass-features) - [36.17. Packaging Related Objects into an Extension](extend-extensions.md) - [36.17.1. Extension Files](extend-extensions.md#extend-extensions-files) - [36.17.2. Extension Relocatability](extend-extensions.md#extend-extensions-relocation) - [36.17.3. Extension Configuration Tables](extend-extensions.md#extend-extensions-config-tables) - [36.17.4. Extension Updates](extend-extensions.md#extend-extensions-updates) - [36.17.5. Installing Extensions Using Update Scripts](extend-extensions.md#extend-extensions-update-scripts) - [36.17.6. Security Considerations for Extensions](extend-extensions.md#extend-extensions-security) - [36.17.7. Extension Example](extend-extensions.md#extend-extensions-example) - [36.18. Extension Building Infrastructure](extend-pgxs.md) In the sections that follow, we will discuss how you can extend the PostgreSQL SQL query language by adding: - functions (starting in [Section 36.3](xfunc.md)) - aggregates (starting in [Section 36.12](xaggr.md)) - data types (starting in [Section 36.13](xtypes.md)) - operators (starting in [Section 36.14](xoper.md)) - operator classes for indexes (starting in [Section 36.16](xindex.md)) - packages of related objects (starting in [Section 36.17](extend-extensions.md))