18PostgreSQL in Python

This example uses the very popular PostgreSQL relational database. If you compare this example to the one described in Chapter 16, “MariaDB in Python,” you'll see many differences in detail. Those are due mostly to the approaches taken by the two database adapters used by the different examples. This example also demonstrates some new database techniques, such as making the database automatically generate ID values and easily creating many records all at once.

PostgreSQL (pronounced post-gres-kyoo-el) is also known as Postgres. (The nickname Postgres is particularly popular with those who find it hard to pronounce PostgreSQL. It's also shorter and, therefore, gives you slightly fewer chances to make typos.) It's a free open source relational database management system.

This example builds a small order database for a coffee supply store named the Brew Crew. Customers place orders that have order items. Figure 18.1 shows the design with some data added to the tables.

First, I'll tell you where you can download and install Postgres. Then I'll explain how to install the Psycopg data adapter for Python.

A representation exhibits the design with some data added to the tables.

Get Beginning Database Design Solutions, 2nd Edition 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.