This book aims to teach the reader how powerful server-side programming can be in PostgreSQL. At the same time, we are going to learn how fun can it be to implement even complex tasks directly in the database engine. This book is structured as follows:
Chapter 1, PostgreSQL Server-side Programming, presents the idea behind server-side programming and the relationship with PostgreSQL.
Chapter 2, Statement Tricks: UPSERTs, RETURNING, and CTEs, explains some of the powerful features of handling SQL statements that are supported by PostgreSQL, such as obtaining automatically computed data, resolving insert conflicts, and performing looping and joins.
Chapter 3, The PL/pgSQL Language, discusses the default language that can be used to implement code in PostgreSQL. This is an imperative, SQL-like language.
Chapter 4, Stored Procedures, teaches you how to store pieces of code in the server in order to execute them and re-use them later.
Chapter 5, PL/Perl and PL/Java, provides insights into how to use Perl and Java within the PostgreSQL server to implement stored procedures and run code.
Chapter 6, Triggers, explains how to run code that can react to data change events and data definition change events.
Chapter 7, Rules and the Query Rewriting System, explains how PostgreSQL can be used to transform statements into other forms.
Chapter 8, Extensions, teaches you how to organize your code in a way that PostgreSQL can handle and manage, as well as how to deal with updates.
Chapter 9, Intra-Process Communication and Background Workers, looks at how to interact with processes (database connections) and how to plug your own processes into the server.
Chapter 10, Custom Data Types, shows how it is possible to extend the already rich PostgreSQL data type to implement your own type with specific business logic.