SQL Statements

Conceptual information on relational databases and tables is of course entirely moot if you don’t have any idea of how to directly interact with your data. From a general perspective, SQL consists entirely of structured statements, with which all data in the database is added, modified, and removed. These statements form the basis for your communication with the PostgreSQL server.

The following sections dissect the anatomy of a SQL statement into its structural pieces, explaining the significance of each, and their relation to one another. The standard PostgreSQL command-line client, psql, provides output to display example PostgreSQL statements.

Our SQL examples commonly take place within an example database called booktown, the database for our imaginary bookstore, Book Town. The output from psql is consistently prefixed with a default prompt style, which looks like this:

booktown=#

Some simpler examples may use our generic test database, testdb, if not specific to the Book Town examples. By default, the psql prompt displays only the name of the connected database and the =# characters indicating that the system is ready for a new command (though you will see that the = symbol will change dynamically as psql tracks the status of SQL input). We display this prompt along with the SQL input and output in order to help familiarize you with the psql output.

Chapter 4 documents psql in more detail, and it is only mentioned here to explain the source and style of this book’s ...

Get Practical PostgreSQL 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.