Skip to content

PGExercises

jguerreroyb edited this page Jul 22, 2019 · 8 revisions

PgExercises is a sample dataset used to power the PostgreSQL Exercises website. The site is comprised of over 80 exercises designed to be used as a companion to the official PostgreSQL documentation. The exercises on the PGExercises site range from simple SELECT statements and WHERE clauses, through JOINs and CASE statements, then on to aggregations, window functions, and recursive queries.

The dataset consists of 3 tables (members, bookings, and facilities) and table relationships as shown in the ER diagram below:

Download and Install YugaByte DB

The latest instructions on how to get up and running are on our Quickstart page here:

https://docs.yugabyte.com/latest/quick-start/

Download Northwind

You can download the Northwind database that is compatible with YugaByte DB from our GitHub repo. Here’s the two files you’ll need:

Enter the YSQL shell

Next run the ysqlsh command to enter the PostgreSQL shell.

ysqlsh (11.2)
Type "help" for help.
postgres=#

Create the Northwind Database

CREATE DATABASE northwind;

Confirm we have the Northwind database by listing out the databases on our cluster.

postgres=# \l

Switch to the Northwind database.

postgres=# \c northwind
You are now connected to database "northwind" as user "postgres".
northwind=# 

Build the Northwind Tables and Objects

northwind=# \i /Users/yugabyte/northwind_ddl.sql

We can verify that all 14 of our tables have been created by executing:

northwind=# \d

Load Sample Data into Northwind

Next, let’s load our database with sample data.

northwind=# \i /Users/yugabyte/northwind_data.sql

Let’s do a simple SELECT to pull data from the customers table to verify we now have some data to play with.

northwind=# SELECT * FROM customers LIMIT 2;

Explore Northwind

The dataset consists of 14 tables and the table relationships are showcased in the entity relationship diagram below:

The dataset contains the following:

  • Suppliers: Suppliers and vendors of Northwind
  • Customers: Customers who buy products from Northwind
  • Employees: Employee details of Northwind traders
  • Products: Product information
  • Shippers: The details of the shippers who ship the products from the traders to the end-customers
  • Orders and Order_Details: Sales Order transactions taking place between the customers & the company

That’s it! Using the command line or your favorite PostgreSQL development or administration tool, you are now ready to start exploring the Northwind database and YugaByte DB features.