Skip to content

Instantly share code, notes, and snippets.

@rieckpil
Last active August 19, 2018 18:52
Show Gist options
  • Save rieckpil/86c3ad340637417875f897e0197075d8 to your computer and use it in GitHub Desktop.
Save rieckpil/86c3ad340637417875f897e0197075d8 to your computer and use it in GitHub Desktop.
Postgres Cheatsheet
# Postgres database as docker container
docker run -p 5432:5432 --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
# creating a table with auto increment primary key prior to PostgreSQL 10
CREATE TABLE category (
ID SERIAL PRIMARY KEY,
DESCRIPTION VARCHAR(255)
);
# creating auto increment primary key since PostgresSQL 10
CREATE TABLE test_new (
id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
payload text
);
INSERT INTO test_new (payload) VALUES ('a'), ('b'), ('c') RETURNING *;
# simple insert
INSERT INTO category (DESCRIPTION) VALUES ('Hello WORLD!');
# creating a new user
CREATE ROLE phil PASSWORD 'hallo' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
# get the version of the PostgreSQL database
SELECT version();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment