Project: YugabyteDB (App Definition and Development / Database)
File: pgexercises.md

title: PgExercises sample database headerTitle: PgExercises linkTitle: PgExercises description: Use the PgExercises sample database on YugabyteDB to learn SQL or test your knowledge. menu: v2.18: identifier: pgexercises parent: sample-data weight: 300 type: docs Install the PostgreSQL-compatible version of PgExercises on the YugabyteDB distributed SQL database. Work through 81 exercises to learn SQL or test your knowledge. You can install and use the PgExercises database using: A local installation of YugabyteDB. To install YugabyteDB, refer to . Using cloud shell or a client shell to connect to a cluster in YugabyteDB Managed. Refer to . To get started with YugabyteDB Managed, refer to . In either case, you use the YugabyteDB SQL shell () CLI to interact with YugabyteDB using . The PgExercises sample database is based on the sample dataset used for the tutorial website. The dataset is for a new country club, with a set of members, facilities, and booking history. The PostgreSQL Exercises website includes 81 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. For further details about the data, see the . The `exercises` database consists of three tables (for members, bookings, and facilities) and the table relationships as shown in the entity relationship diagram. The PGExercise SQL scripts reside in the `share` folder of your YugabyteDB or client shell installation. They can also be found in the . The following files will be used for this exercise: Creates the tables and other database objects Loads the sample data Follow the steps here to install the PgExercises sample database. If you are using a local installation of YugabyteDB, run the `ysqlsh` command from the `yugabyte` root directory. ```sh $ ./bin/ysqlsh ``` If you are connecting to YugabyteDB Managed, open the , or for your cluster from the `yugabyte-client` bin directory. To create the `exercises` database, run the following SQL `CREATE DATABASE` command. ```plpgsql CREATE DATABASE exercises; ``` Confirm that you have the `exercises` database by listing the databases on your cluster using the `\l` command. ```plpgsql yugabyte=# \l ``` Connect to the `exercises` database. ```plpgsql yugabyte=# \c exercises ``` ```output You are now connected to database "exercises" as user "yugabyte". exercises=# ``` To build the tables and database objects, run the `\i` command. ```plpgsql exercises=# \i share/clubdata_ddl.sql ``` You can verify that all three tables have been created by running the `\d` command. ```plpgsql exercises=# \d ``` To load the `exercises` database with sample data, run the following command to execute commands in the file. ```plpgsql exercises=# \i share/clubdata_data.sql ``` You can verify that you have data to work with by running the following `SELECT` statement to pull data from the `bookings` table. ```plpgsql exercises=# SELECT * FROM bookings LIMIT 5; ``` You are now ready to start working through the exercises using YugabyteDB as the backend. The 81 exercises at the PostgreSQL Exercises website are broken into the following major sections. YugabyteDB returns the same results as expected based on the solutions on the PostgreSQL Exercises website, with one exception. In the exercise, YugabyteDB returns results with a sort order of strings different than in PostgreSQL due to .