PostgreSQL sample databases for practice
PostgreSQL is the open-source database most often used for new applications and data work, with strict types, real booleans and dates, and a rich set of functions. Here are 13 practice databases as PostgreSQL scripts, each with six questions whose answers were produced by PostgreSQL 15.18.
Sales orders
Superstore-style retail orders with sales, cost, discount and profit.
PostgreSQLOnline store
Four related tables (customers, products, orders, order items) for JOIN practice.
PostgreSQLEmployees
An HR table: departments, titles, hire dates, salaries and managers.
PostgreSQLCustomers
A customer list with segments, order counts, lifetime spend and activity.
PostgreSQLInventory
Stock levels, reorder points and stock value across four warehouses.
PostgreSQLStudent grades
Test scores, averages, letter grades and attendance for grades 9-12.
PostgreSQLWebsite traffic
Daily sessions, users, bounce rate and conversions by channel.
PostgreSQLMarketing campaigns
Budget, spend, impressions, clicks, CPA and ROAS per campaign.
PostgreSQLCall center
Calls with queue, reason, wait and handle time, resolution and CSAT.
PostgreSQLRestaurant orders
Order lines with menu items, tickets, order type and payment.
PostgreSQLInvoices
Invoices with due dates, payment dates, tax, status and days late.
PostgreSQLBank transactions
One fictional account: debits, credits, categories and a running balance.
PostgreSQLMessy customers
A customer list with duplicates, blanks, mixed dates and text in number columns.
PostgreSQL SQL in these exercises
The questions are the same on every engine; what changes is the syntax. These are the PostgreSQL-specific parts you will meet:
- to_char(date, 'YYYY-MM') formats a date as year-month text.
- EXTRACT(YEAR FROM date) returns a number; ::int casts it to integer.
- Subtracting one DATE from another returns the number of days as an integer.
- LIMIT n at the end returns the first n rows.
- Yes/no columns are real BOOLEAN values, so they can be used directly in WHERE and CASE.
- || joins strings.
- substr(text, start, length) cuts out part of a string.
- Multiplying by 1.0 avoids integer division.
- AVG of an integer column returns a numeric, so no cast is needed.
- RANK() and ROW_NUMBER() OVER (PARTITION BY ...) work on any supported version.
- LENGTH counts characters.
- Text comparison is case-sensitive by default, so upper- and lower-case versions of an email count separately.
Other engines
SQLite · MySQL · SQL Server · DuckDB
The data is fictional and released under CC0. AdventureWorks, Northwind and Sakila are well-known sample databases from their vendors; we do not copy them here.