Chapter 38. Extending SQL

|   Chapter 38. Extending SQL   |                             |                          |                  |                        |
|:-----------------------------:|-----------------------------|--------------------------|------------------|------------------------|
|[Prev](server-programming.html)|[Up](server-programming.html)|Part V. Server Programming|[Home](index.html)| [Next](extend-how.html)|

---

## Chapter 38. Extending SQL

**Table of Contents**

[38.1. How Extensibility Works](extend-how.html)[38.2. The PostgreSQL Type System](extend-type-system.html)[38.2.1. Base Types](extend-type-system.html#id-1.8.3.5.9)[38.2.2. Container Types](extend-type-system.html#id-1.8.3.5.10)[38.2.3. Domains](extend-type-system.html#EXTEND-TYPE-SYSTEM-DOMAINS)[38.2.4. Pseudo-Types](extend-type-system.html#id-1.8.3.5.12)[38.2.5. Polymorphic Types](extend-type-system.html#EXTEND-TYPES-POLYMORPHIC)[38.3. User-Defined Functions](xfunc.html)[38.4. User-Defined Procedures](xproc.html)[38.5. Query Language (SQL) Functions](xfunc-sql.html)[38.5.1. Arguments for SQL Functions](xfunc-sql.html#XFUNC-SQL-FUNCTION-ARGUMENTS)[38.5.2. SQL Functions on Base Types](xfunc-sql.html#XFUNC-SQL-BASE-FUNCTIONS)[38.5.3. SQL Functions on Composite Types](xfunc-sql.html#XFUNC-SQL-COMPOSITE-FUNCTIONS)[38.5.4. SQL Functions with Output Parameters](xfunc-sql.html#XFUNC-OUTPUT-PARAMETERS)[38.5.5. SQL Procedures with Output Parameters](xfunc-sql.html#XFUNC-OUTPUT-PARAMETERS-PROC)[38.5.6. SQL Functions with Variable Numbers of Arguments](xfunc-sql.html#XFUNC-SQL-VARIADIC-FUNCTIONS)[38.5.7. SQL Functions with Default Values for Arguments](xfunc-sql.html#XFUNC-SQL-PARAMETER-DEFAULTS)[38.5.8. SQL Functions as Table Sources](xfunc-sql.html#XFUNC-SQL-TABLE-FUNCTIONS)[38.5.9. SQL Functions Returning Sets](xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET)[38.5.10. SQL Functions Returning `TABLE`](xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-TABLE)[38.5.11. Polymorphic SQL Functions](xfunc-sql.html#XFUNC-SQL-POLYMORPHIC-FUNCTIONS)[38.5.12. SQL Functions with Collations](xfunc-sql.html#id-1.8.3.8.21)[38.6. Function Overloading](xfunc-overload.html)[38.7. Function Volatility Categories](xfunc-volatility.html)[38.8. Procedural Language Functions](xfunc-pl.html)[38.9. Internal Functions](xfunc-internal.html)[38.10. C-Language Functions](xfunc-c.html)[38.10.1. Dynamic Loading](xfunc-c.html#XFUNC-C-DYNLOAD)[38.10.2. Base Types in C-Language Functions](xfunc-c.html#XFUNC-C-BASETYPE)[38.10.3. Version 1 Calling Conventions](xfunc-c.html#id-1.8.3.13.7)[38.10.4. Writing Code](xfunc-c.html#id-1.8.3.13.8)[38.10.5. Compiling and Linking Dynamically-Loaded Functions](xfunc-c.html#DFUNC)[38.10.6. Composite-Type Arguments](xfunc-c.html#id-1.8.3.13.10)[38.10.7. Returning Rows (Composite Types)](xfunc-c.html#id-1.8.3.13.11)[38.10.8. Returning Sets](xfunc-c.html#XFUNC-C-RETURN-SET)[38.10.9. Polymorphic Arguments and Return Types](xfunc-c.html#id-1.8.3.13.13)[38.10.10. Shared Memory and LWLocks](xfunc-c.html#XFUNC-SHARED-ADDIN)[38.10.11. Using C++ for Extensibility](xfunc-c.html#EXTEND-CPP)[38.11. Function Optimization Information](xfunc-optimization.html)[38.12. User-Defined Aggregates](xaggr.html)[38.12.1. Moving-Aggregate Mode](xaggr.html#XAGGR-MOVING-AGGREGATES)[38.12.2. Polymorphic and Variadic Aggregates](xaggr.html#XAGGR-POLYMORPHIC-AGGREGATES)[38.12.3. Ordered-Set Aggregates](xaggr.html#XAGGR-ORDERED-SET-AGGREGATES)[38.12.4. Partial Aggregation](xaggr.html#XAGGR-PARTIAL-AGGREGATES)[38.12.5. Support Functions for Aggregates](xaggr.html#XAGGR-SUPPORT-FUNCTIONS)[38.13. User-Defined Types](xtypes.html)[38.13.1. TOAST Considerations](xtypes.html#XTYPES-TOAST)[38.14. User-Defined Operators](xoper.html)[38.15. Operator Optimization Information](xoper-optimization.html)[38.15.1. `COMMUTATOR`](xoper-optimization.html#id-1.8.3.18.6)[38.15.2. `NEGATOR`](xoper-optimization.html#id-1.8.3.18.7)[38.15.3. `RESTRICT`](xoper-optimization.html#id-1.8.3.18.8)[38.15.4. `JOIN`](xoper-optimization.html#id-1.8.3.18.9)[38.15.5. `HASHES`](xoper-optimization.html#id-1.8.3.18.10)[38.15.6. `MERGES`](xoper-optimization.html#id-1.8.3.18.11)[38.16. Interfacing Extensions to Indexes](xindex.html)[38.16.1. Index Methods and Operator Classes](xindex.html#XINDEX-OPCLASS)[38.16.2. Index Method Strategies](xindex.html#XINDEX-STRATEGIES)[38.16.3. Index Method Support Routines](xindex.html#XINDEX-SUPPORT)[38.16.4. An Example](xindex.html#XINDEX-EXAMPLE)[38.16.5. Operator Classes and Operator Families](xindex.html#XINDEX-OPFAMILY)[38.16.6. System Dependencies on Operator Classes](xindex.html#XINDEX-OPCLASS-DEPENDENCIES)[38.16.7. Ordering Operators](xindex.html#XINDEX-ORDERING-OPS)[38.16.8. Special Features of Operator Classes](xindex.html#XINDEX-OPCLASS-FEATURES)[38.17. Packaging Related Objects into an Extension](extend-extensions.html)[38.17.1. Extension Files](extend-extensions.html#id-1.8.3.20.11)[38.17.2. Extension Relocatability](extend-extensions.html#EXTEND-EXTENSIONS-RELOCATION)[38.17.3. Extension Configuration Tables](extend-extensions.html#EXTEND-EXTENSIONS-CONFIG-TABLES)[38.17.4. Extension Updates](extend-extensions.html#id-1.8.3.20.14)[38.17.5. Installing Extensions Using Update Scripts](extend-extensions.html#id-1.8.3.20.15)[38.17.6. Security Considerations for Extensions](extend-extensions.html#EXTEND-EXTENSIONS-SECURITY)[38.17.7. Extension Example](extend-extensions.html#EXTEND-EXTENSIONS-EXAMPLE)[38.18. Extension Building Infrastructure](extend-pgxs.html)

[]()

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

* functions (starting in [Section 38.3](xfunc.html))

* aggregates (starting in [Section 38.12](xaggr.html))

* data types (starting in [Section 38.13](xtypes.html))

* operators (starting in [Section 38.14](xoper.html))

* operator classes for indexes (starting in [Section 38.16](xindex.html))

* packages of related objects (starting in [Section 38.17](extend-extensions.html))

---

|[Prev](server-programming.html)|[Up](server-programming.html)|    [Next](extend-how.html)   |
|:------------------------------|:---------------------------:|-----------------------------:|
|  Part V. Server Programming   |     [Home](index.html)      | 38.1. How Extensibility Works|

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>