PostgreSQL

Learning Objectives

By the end of this lesson, you will be able to...

- Describe Postgres

- Use psql in the terminal

- Create a db

- Create a table

- Insert values

- Query the table to see values

/prəˌnənsē ˈ āSH(ə)n/

Both PostgreSQL and
Postgres are correct spellings


Pronounced Post-Gres-Q-L or Post-Gres

Incorrect spellings are PostGres, PostGreSQL, PostgresQL, et al.

 

What is it?

Open source object-relational
database system


RDBMS: Relational database management system

 

Fully ACID compliant (Atomicity, Consistency, Isolation, Durability)

Who owns it?

You!

Everyone!

 

The development of Postgres is completely driven by open source and the community

 

Who uses it?

What is ACID?

Atomicity: Each transaction is "all or nothing"

Consistency: Any transaction will bring the database from one valid state to another.

Isolation: The concurrent execution of transactions results in a system state that would be obtained if transactions were executed serially, i.e., one after the other.

Durability: Once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors.

 

How do we use it?

postgres: The database itself

 

psql: PostgreSQL interactive terminal

 

Client Applications (Etc.)

Driver: such as pg

ORM: Such as Sequelize, Massive, bookshelf, knex

psql - terminal

Here you can do all sort of things:

  • Create Databases, tables, insert values
  • List tables, select data
  • *SQL Statements*
  • Also: Delete everything. Blame a coworker. Coworker gets fired. Feel guilty the rest of your life.

Need help on a command? Use:    \h

ctrl+d or \q
to quit

create/connect to DB

list all databases

q to quit

create/connect to DB

create a database

q to quit

NOTE THE CHANGE IN CAPS

create/connect to DB

Connect to the DB

While in psql

From the terminal

NOTE THE CHANGE IN PROMPT

creating a table

create table

view tables

view columns

creating a record

commands

\h - Get help
\c - Connect to a database
\l - List all databases you can see in Postgres
\dt - Describe all tables in the current database
\d [tablename] - Describe the columns of a table
\q - Quit

Learning Objectives

By the end of this lesson, you will be able to...

- Describe Postgres

- Use psql in the terminal

- Create a db

- Create a table

- Insert values

- Query the table to see values

Let's practice.

Create a database called 'psqlPractice'

Create tables: 'food', 'book', 'movie'

(each with an id, name, and entry)

Insert values for each peer sitting at your pod


Do a select statement to see all the data.

 

64-intro-PostgreSQL

By Michelle Bergquist

64-intro-PostgreSQL

  • 124
Loading comments...

More from Michelle Bergquist