🛢️
PostgreSQL
Grokking Algorithm
  • Content
  • Environment
  • Getting Started
    • Introduction
      • What is PostgreSQL
      • Introduction to PostgreSQL sample database
    • Postgres on Windows
      • Install PostgreSQL on Windows
      • Connect to PostgreSQL database server
      • Load the sample database into the PostgreSQL database server
    • Postgres on Linux
    • Install PostgreSQL on macOS
  • Basic
    • Querying Data
      • SELECT
      • Column alias
      • ORDER BY
      • SELECT DISTINCT
    • Filtering Data
      • WHERE
      • AND
      • OR
      • LIMIT
      • FETCH
      • IN
      • BETWEEN
      • LIKE
      • IS NULL
    • Joining Multiple tables
      • Joins
      • Table aliases
      • INNER JOIN
      • LEFT JOIN
      • RIGHT JOIN
      • SELF JOIN
      • FULL OUTER JOIN
      • CROSS JOIN
      • NATURAL JOIN
    • Grouping data
      • GROUP BY
      • HAVING
    • Set Operations
      • UNION
      • INTERSECT
      • EXCEPT
    • Grouping sets, Cube, and Rollup
      • Grouping sets
      • CUBE
      • ROLLUP
    • Subquery
      • Subquery
      • ANY
      • ALL
      • EXISTS
    • Common Table Expressions
      • PostgreSQL CTE
      • Recursive query using CTEs
    • Modifying Data
      • Insert
      • Insert multiple rows
      • Update
      • Update join
      • Delete
      • Upsert
    • Transactions
      • PostgreSQL Transaction
    • Import & Export Data
      • Import CSV file into Table
      • Export PostgreSQL Table to CSV file
    • Managing Tables
      • Data types
      • Create a table
      • Select into
      • Create table as
      • Auto-increment
      • Sequences
      • Identity column
      • Alter table
      • Rename table
      • Add column
      • Drop column
      • Change column data type
      • Rename column
      • Drop table
      • Truncate table
      • Temporary table
      • Copy a table
    • Understanding PostgreSQL constraints
      • Primary key
      • Foreign key
      • UNIQUE constraint
      • CHECK constraint
      • NOT NULL constraint
    • PostgreSQL Data Types in Depth
      • Boolean
      • CHAR, VARCHAR and TEXT
      • NUMERIC
      • Integer
      • DATE
      • Timestamp
      • Interval
      • TIME
      • UUID
      • Array
      • hstore
      • JSON
      • User-defined data types
  • Advanced
  • PG-PGSQL
  • Functions
  • Adminstration
  • API
Powered by GitBook
On this page
  • Initial Setup
  • Sample Database for use with PostgreSQL
  • Copy file to docker container
  • Restore database
  • Keep learning . . . 👨‍💻

Was this helpful?

Edit on GitHub

Environment

Initial Setup

We have a makefile that will help you setup the database and run the queries. We use Docker to run the database.

Create Database with Docker

$ make run 

Login to container with Docker

$ make bash

Login to Database with Docker

$ make exec

Start container

$ make start

Stop container

$ make stop

Delete container

$ make delete

Sample Database for use with PostgreSQL

First, extract the file. Second, you need to login to docker container:

Copy file to docker container

$ docker cp <file_path> <container_name>:<file_path>

Example:

$ docker cp ~/Downdloads/dvdrental.tar postgres:/

After login to docker container, you need to restore the database:

Restore database

$ pg_restore -U postgres -d <db_name> <file_path>

Exapmle:

$ pg_restore -U postgres -d dvdrental /dvdrental.tar

Keep learning . . . 👨‍💻

PreviousContentNextGetting Started

Last updated 1 year ago

Was this helpful?

Please, download this db:

Download Link