Skip to content

Instantly share code, notes, and snippets.

@thalesbruno
Created December 18, 2022 09:24
Show Gist options
  • Save thalesbruno/9c94ce752b29f0eed954ceca41aadefd to your computer and use it in GitHub Desktop.
Save thalesbruno/9c94ce752b29f0eed954ceca41aadefd to your computer and use it in GitHub Desktop.
PostgreSQL Basic Guide

PostgreSQL Basic Guide

Primary Keys

Autoincrement numeric id

CREATE TABLE users (
  id SERIAL PRIMARY KEY
);

Autogenerated UUID id

CREATE TABLE products (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY
);

ENUM type

Create an ENUM type

CREATE TYPE order_status AS ENUM ('open', 'pending', 'closed', 'canceled');

Use created type

CREATE TABLE order (
  id SERIAL PRIMARY KEY,
  status order_status
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment