Last active
August 19, 2018 18:52
-
-
Save rieckpil/86c3ad340637417875f897e0197075d8 to your computer and use it in GitHub Desktop.
Postgres Cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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