AI Hints
Home›PostgreSQL Tutorial›Databases, Tables and psql
PostgreSQL · Lesson 5 of 120

Meet Riverside Books

Our practice shop.

⏱ 2 min read▶ Video at 3:33🎓 Free
Watch this lesson in the PostgreSQL courseWatch on YouTube ↗Full PostgreSQL course

Riverside Books is a small online bookshop. It has customers, books, orders, the items in each order, staff, and reviews. We'll use its database for most of the course.

  • Customers
  • Books
  • Orders
  • Reviews

The tables

Customers are people who shop. Books are what we sell. Orders link a customer to a date, and order items list the books in each order. Staff and reviews complete the picture.

TableRowsHolds
customers500who buys
books30what we sell
orders1,598when they buy
order_items2,363which books
reviews240what they think

Count every table

A quick way to check a database is to count rows. Union all stacks several counts into one result. Run it. The numbers match the table we just saw.

query.sqlsql
SELECT 'customers' AS tbl, count(*) FROM customers
UNION ALL SELECT 'books',       count(*) FROM books
UNION ALL SELECT 'orders',      count(*) FROM orders
UNION ALL SELECT 'order_items', count(*) FROM order_items
UNION ALL SELECT 'reviews',     count(*) FROM reviews;
Output
     tbl     | count
-------------+-------
 customers   |   500
 books       |    30
 orders      |  1598
 order_items |  2363
 reviews     |   240
(5 rows)

Summary

Riverside Books has customers, books, orders, order items, staff and reviews. Next, psql's handy backslash commands.

Key takeaways
  • Six tables
  • Real orders
  • All course
Next up: psql Meta-commands — backslash shortcuts