Postgres

A schema is a named collection of tables.

Data type

serial

CREATE TABLE table_name(
    id SERIAL
);

is equal to

CREATE SEQUENCE table_name_id_seq;

CREATE TABLE table_name (
    id integer NOT NULL DEFAULT nextval('table_name_id_seq')
);

ALTER SEQUENCE table_name_id_seq
OWNED BY table_name.id;

Result will be

id| integer || not null | nextval('users_id_seq'::regclass)

Indexes:
    "users_pkey" PRIMARY KEY, btree (id)

Start on your mac

pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
select now();

-------------------------------
 2018-08-18 14:30:29.221862-07
(1 row)

Create table

create table users (id int primary key not null);

Show tables

\dt

Show specific table

\d users

Run command from external file

\i commands.sql

create table with constraints

default value

is_email_confirmed boolean default FALSE
  • Time now
createdAt timestamp default 'now'

check value

body text check(length(body) < 180)

unique value

email unique

not null value

body text not null

primary key

id primary key

serial (auto increment)

id serial

results matching ""

    No results matching ""