## Chapter 38. Extending SQL

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

- functions (starting in Section 38.3)

- aggregates (starting in Section 38.10)

- data types (starting in Section 38.11)

- operators (starting in Section 38.12)

- operator classes for indexes (starting in Section 38.14)

- packages of related objects (starting in Section 38.15)

## 38.1. How Extensibility Works

Postgres Pro Enterprise is extensible because its operation is catalog-driven. If you are familiar with standard relational database systems, you know that they store information about databases, tables, columns, etc., in what are commonly known as system catalogs. (Some systems call this the data dictionary.) The catalogs appear to the user as tables like any other, but the DBMS stores its internal bookkeeping in them. One key difference between Postgres Pro Enterprise and standard relational database systems is that Postgres Pro Enterprise stores much more information in its catalogs: not only information about tables and columns, but also information about data types, functions, access methods, and so on. These tables can be modified by the user, and since Postgres Pro Enterprise bases its operation on these tables, this means that Postgres Pro Enterprise can be extended by users. By comparison, conventional database systems can only be extended by changing hardcoded procedures in the source code or by loading modules specially written by the DBMS vendor.

The Postgres Pro Enterprise server can moreover incorporate user-written code into itself through dynamic loading. That is, the user can specify an object code file (e.g., a shared library) that implements a new type or function, and Postgres Pro Enterprise will load it as required. Code written in SQL is even more trivial to add to the server. This ability to modify its operation “on the fly” makes Postgres Pro Enterprise uniquely suited for rapid prototyping of new applications and storage structures.