2nd Edition. — Independently published, 2021. — 457 p.
This book is intended for developers working on applications that use a database server. The book specifically addresses the PostgreSQL RDBMS: it is the world’s most advanced Open-Source database, just like it says in the tagline on the official website. By the end of this book, you’ll know why, and you’ll agree! I wanted to write this book after having worked with many customers who were making use of only a fraction of what SQL and PostgreSQL are capable of delivering. In most cases, the developers I met with didn’t know what it was possible to achieve in SQL. As soon as they realized — or more exactly, as soon as they were shown what’s possible to achieve — , replacing hundreds of lines of application code with a small and efficient SQL query, then in some cases they would nonetheless not know how to integrate a raw SQL query in their code base. Integrating a SQL query and thinking about SQL as code means using the same advanced tooling that we use when using other programming languages: versioning, automated testing, code reviewing, and deployment. This is more about the developer’s work ow than the SQL code itself…
In this book, you will learn best practices that help with integrating SQL into your workflow, and through the many examples provided, you’ll see all the reasons why you might be interested in doing more in SQL. Primarily, it means writing fewer lines of code. As Dijkstra said, we should count lines of code as lines spent, so by learning how to use SQL you will be able to spend less to write the same application!
Each part of “The Art of PostgreSQL” can be read on its own, or you can read this book from the first to the last page in the order of the parts and chapters therein. A great deal of thinking has been put into the ordering of the parts so that reading “The Art of PostgreSQL” in a linear fashion should provide the best experience.
The skill progression throughout the book is not linear. Each time a new SQL concept is introduced, it is presented with simple enough queries, to make it possible to focus on the new notion. Then, more queries are introduced to answer more interesting business questions. The complexity of the queries usually advances throughout a given part, chapter after chapter. Sometimes, when a new chapter introduces a new SQL concept, complexity is reset to very simple queries again. That’s because for most people, learning a new skill set does not happen linearly. Having this kind of difficult organization also makes it easier to dive into a given chapter out-of-order.
The introduction of this book intends to convince application developers such as you, dear reader, that there’s more to SQL than you might think. It begins with a very simple data set and simple enough queries, that we compare to their equivalent Python code. Then we expand from there with a very important trick that’s not well-known and a pretty advanced variation of it. A simple Python application is introduced as a practical example illustrating the different answers provided. In particular, this part insists on when to use SQL to implement business logic.