Pagila

PostgreSQL Sample Database
Alternatives To Pagila
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Netdata67,182
15 hours ago283gpl-3.0C
The open-source observability platform everyone needs!
Prisma36,31044214 hours ago4,993September 24, 20223,059apache-2.0TypeScript
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
Dbeaver36,079
14 hours ago1,966apache-2.0Java
Free universal database tool and SQL client
Metabase35,878
14 hours ago1June 08, 20223,598otherClojure
The simplest, fastest way to get business intelligence and analytics to everyone in your company :yum:
Typeorm32,9541,9943,70417 hours ago784October 05, 20232,283mitTypeScript
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Quivr28,400
2 days ago91apache-2.0TypeScript
Your GenAI Second Brain 🧠 A personal productivity assistant (RAG) ⚡️🤖 Chat with your docs (PDF, CSV, ...) & apps using Langchain, GPT 3.5 / 4 turbo, Private, Anthropic, VertexAI, Ollama, LLMs, that you can share with users ! Local & Private alternative to OpenAI GPTs & ChatGPT powered by retrieval-augmented generation.
Directus24,77923914 hours ago95November 16, 2023467otherTypeScript
The Modern Data Stack 🐰 — Directus is an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database.
Postgrest21,836
416 hours ago37July 12, 2022239mitHaskell
REST API for any Postgres database
Mindsdb19,973
15 hours ago449December 07, 2023432otherPython
The platform for building custom AI, enabling smarter organizations.
Shardingsphere19,2573315 hours ago7June 04, 20201,203apache-2.0Java
Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Alternatives To Pagila
Select To Compare


Alternative Project Comparisons
Readme

Pagila

Pagila started as a port of the Sakila example database available for MySQL, which was originally developed by Mike Hillyer of the MySQL AB documentation team. It is intended to provide a standard schema that can be used for examples in books, tutorials, articles, samples, etc.

Pagila has been tested against PostgreSQL 12 and above.

All the tables, data, views, and functions have been ported; some of the changes made were:

  • Changed char(1) true/false fields to true boolean fields
  • The last_update columns were set with triggers to update them
  • Added foreign keys
  • Removed 'DEFAULT 0' on foreign keys since it's pointless with real FK's
  • Used PostgreSQL built-in fulltext searching for fulltext index. Removed the need for the film_text table.
  • The rewards_report function was ported to a simple SRF
  • Added JSONB data

The pagila database is made available under PostgreSQL license.

EXAMPLE QUERY

Find late rentals:

SELECT
	CONCAT(customer.last_name, ', ', customer.first_name) AS customer,
	address.phone,
	film.title
FROM
	rental
	INNER JOIN customer ON rental.customer_id = customer.customer_id
	INNER JOIN address ON customer.address_id = address.address_id
	INNER JOIN inventory ON rental.inventory_id = inventory.inventory_id
	INNER JOIN film ON inventory.film_id = film.film_id
WHERE
	rental.return_date IS NULL
	AND rental_date < CURRENT_DATE
ORDER BY
	title
LIMIT 5;

FULLTEXT SEARCH

Fulltext functionality is built in PostgreSQL, so parts of the schema exist in the main schema file.

Example usage:

SELECT * FROM film WHERE fulltext @@ to_tsquery('fate&india');

pgAdmin is included in the docker-compose.

Navigate to the URL : http://localhost:5050/ Default Username: [email protected] Default Password: root

PARTITIONED TABLES

The payment table is designed as a partitioned table with a 7 month timespan for the date ranges.

INSTALL NOTE

The pagila-data.sql file and the pagila-insert-data.sql both contain the same data, the former using COPY commands, the latter using INSERT commands, so you only need to install one of them. Both formats are provided for those who have trouble using one version or another, and for instructors who want to point out the longer data loading time with the latter. You can load them via psql, pgAdmin, etc.

Since JSONB data is quite large to store on Github, the backup is not a plain SQL file. You can still use psql/pgAdmin, etc. to load pagila-schema-jsonb.sql, however please use pg_restore to load jsonb data files:

pg_restore /usr/share/pagila/pagila-data-yum-jsonb.sql -U postgres -d pagila
pg_restore /usr/share/pagila/pagila-data-apt-jsonb.sql -U postgres -d pagila

VERSION HISTORY

Version 3.0.0

Version 2.1.0

  • Replace varchar(n) with text (David Fetter)
  • Match foreign key and primary key data type in some tables (Ganeshan Venkataraman)
  • Change CREATE TABLE statement for customer table to use DEFAULT nextval('customer_customer_id_seq'::regclass) for customer_id field instead of SERIAL (Adrian Klaver).

Version 2.0

  • Update schema for newer PostgreSQL versions
  • Remove RULE for partitioning, add trigger support.
  • Update years in sample data.
  • Remove ARTICLES section from README, all links are dead.

Version 0.10.1

  • Add pagila-data-insert.sql file, added articles section

Version 0.10

  • Support for built-in fulltext. Add enum example

Version 0.9

  • Add table partitioning example

Version 0.8

  • First release of pagila

CREATE DATABASE ON DOCKER

  1. On terminal pull the latest postgres image:
 docker pull postgres
  1. Run image:
 docker run --name postgres -e POSTGRES_PASSWORD=secret -d postgres
  1. Run postgres and create the database:
docker exec -it postgres psql -U postgres
psql (13.1 (Debian 13.1-1.pgdg100+1))
Type "help" for help.

postgres=# CREATE DATABASE pagila;
postgres-# CREATE DATABASE
postgres=\q
  1. Create all schema objetcs (tables, etc) replace <local-repo> by your local directory :
cat <local-repo>/pagila-schema.sql | docker exec -i postgres psql -U postgres -d pagila
  1. Insert all data:
cat <local-repo>/pagila-data.sql | docker exec -i postgres psql -U postgres -d pagila
  1. Done! Just use:
docker exec -it postgres psql -U postgres
postgres
psql (13.1 (Debian 13.1-1.pgdg100+1))
Type "help" for help.

postgres=# \c pagila
You are now connected to database "pagila" as user "postgres".
pagila=# \dt
                    List of relations
 Schema |       Name       |       Type        |  Owner
--------+------------------+-------------------+----------
 public | actor            | table             | postgres
 public | address          | table             | postgres
 public | category         | table             | postgres
 public | city             | table             | postgres
 public | country          | table             | postgres
 public | customer         | table             | postgres
 public | film             | table             | postgres
 public | film_actor       | table             | postgres
 public | film_category    | table             | postgres
 public | inventory        | table             | postgres
 public | language         | table             | postgres
 public | payment          | partitioned table | postgres
 public | payment_p2022_01 | table             | postgres
 public | payment_p2022_02 | table             | postgres
 public | payment_p2022_03 | table             | postgres
 public | payment_p2022_04 | table             | postgres
 public | payment_p2022_05 | table             | postgres
 public | payment_p2022_06 | table             | postgres
 public | payment_p2022_07 | table             | postgres
 public | rental           | table             | postgres
 public | staff            | table             | postgres
 public | store            | table             | postgres
(21 rows)

pagila=#
```

CREATE DATABASE ON DOCKER-COMPOSE

  1. Run:
docker-compose up
  1. Done! Just use:
docker exec -it pagila psql -U postgres

postgres
psql (13.1 (Debian 13.1-1.pgdg100+1))
Type "help" for help.

postgres=# \c pagila
You are now connected to database "pagila" as user "postgres".
pagila=# \dt
                    List of relations
 Schema |       Name       |       Type        |  Owner
--------+------------------+-------------------+----------
 public | actor            | table             | postgres
 public | address          | table             | postgres
 public | category         | table             | postgres
 public | city             | table             | postgres
 public | country          | table             | postgres
 public | customer         | table             | postgres
 public | film             | table             | postgres
 public | film_actor       | table             | postgres
 public | film_category    | table             | postgres
 public | inventory        | table             | postgres
 public | language         | table             | postgres
 public | payment          | partitioned table | postgres
 public | payment_p2022_01 | table             | postgres
 public | payment_p2022_02 | table             | postgres
 public | payment_p2022_03 | table             | postgres
 public | payment_p2022_04 | table             | postgres
 public | payment_p2022_05 | table             | postgres
 public | payment_p2022_06 | table             | postgres
 public | payment_p2022_07 | table             | postgres
 public | rental           | table             | postgres
 public | staff            | table             | postgres
 public | store            | table             | postgres
(21 rows)

pagila=#

Popular Database Projects
Popular Postgresql Projects
Popular Data Storage Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Database
Postgresql
Table
Schema
Plpgsql
Partitioning
Fulltext