Installing postgres with brew + basics

Step 1: Install postgres

brew install postgres

Step 2: Start postgres server

brew services start postgresql

Step 3: create a database called book

createdb book

list your tables with: \l

Step 4: opened the database shell instance for “book”

psql book

Step 5: create a table

create table dids (

body text, date timestamp, code text);

list your tables with: \dt

Step 6: add some rows

RULES: SINGLE QUOTES ONLY

INSERT INTO dids (body, date)

VALUES ('paired with core', NOW());

INSERT INTO dids (body, date)

VALUES ('remembered that SQL is SINGLE QUOTES ONLY', NOW());

 

OOPS – we forgot to add a primary key

Step 7: Add a column before wreck yourself

alter table dids add column id serial primary key;

look at the table schema with: \d <table_name>

Step 8: Query your new database!

select * from dids

 

Installed with:

Homebrew 1.7.1

postgres (PostgreSQL) 10.4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s