Creating Custom Functions

PostgreSQL includes a number of predefined functions to help in data manipulation (see Chapter 4, “PostgreSQL Functions,” for a full listing). Many of the ones included are general-purpose functions that aid in converting, formatting, or aggregating data.

There are many cases in which the system would benefit from the existence of user-defined functions. Functions are particularly useful when the same information needs to be accessed repeatedly. In these cases, it is possible to create a user-defined function that is stored within the server.

Typically, when a function is created, a query plan is precompiled and stored as ready to be executed. This benefits system speed tremendously because the client application only ...

Get PostgreSQL Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.