-
Notifications
You must be signed in to change notification settings - Fork 0
PostgreSQL commands
Daisho Komiyama edited this page Dec 27, 2022
·
28 revisions
docker pull postgres:15
docker run -e POSTGRES_PASSWORD=<your_password> --name=<your_container_name> --rm -d -p 5432:5432 postgres:15
-e = environment variable (i.e., POSTGRES_PASSWORD
)
-d = detaches (runs in the background)
-p = exposes to port
docker exec -u postgres -it <your_container_name> psql
-u = user
psql = a name of the command that we're running inside of the container, which is the Postgres client, psql
is the client to run queries against the database
\l
\q
\?
\!
i.e., to print the list of contents \! ls
\d
CREATE DATABASE recipeguru;
\c recipeguru;
CREATE TABLE ingredients (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
title VARCHAR (255) UNIQUE NOT NULL
);
INSERT INTO ingredients (title) VALUES ('bell pepper');
SELECT * FROM ingredients;
You'll get,
id | title
----+-------------
1 | bell pepper
(1 row)