DataBrighten

    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.

    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.