SlideShare a Scribd company logo
Introduction to
PostgreSQL
Joel Brewer
@jahbrewski
brewerdigital.com
• Introduction to databases
• Introduction to PostgreSQL
• CRUD
• Create
• Read/query
• Update
• Destroy
• Joins
Overview
What’s a database?
• A database stores data!
• It is a collection of information that is organized so
that it can be easily accessed, managed, and
updated
Why do I care?
• If you’re building a web application, you’re going to
have data to store
• What data do these websites store?
• Facebook (users, profiles, groups, events,
businesses)
• Twitter (users, tweets)
• CNN (articles, comments)
What’s PostgreSQL?
• PostgreSQL (“post-gress-Q-L”) is an open source
object-relational database system
• Open source = free!
• Object - some object-oriented paradigms are
natively supported, such as objects, classes, and
inheritance
• Relational - database is structured to recognize
relations among stored items of information
Let’s make a database
$ createdb testdb
$ psql testdb
=> SELECT version();
Note: to exit psql just type “q”
Let’s make a table
=> CREATE TABLE spaceship (
nickname varchar(35),
crew_size int,
commission_date date
);
CRUD
• CRUD (create, read, update, delete) are the four
basic functions you perform on a database
Create
• Examples:
• Creating a new account on Facebook
• Posting a picture on Instagram
• Creating a new tweet on Twitter
Read
• Examples:
• Browsing your Facebook timeline
• Looking at pictures on Instagram
• Reading the latest article on CNN
Update
• Examples:
• Changing your password
• Editing a comment
• Changing your relationship status on Facebook
Destroy
• Examples:
• Deleting a picture on Facebook (well, maybe…)
• Deleting a tweet on Twitter
• Unfriending somebody on Facebook
Create
• SQL uses the INSERT statement to create a new
row
=> INSERT INTO spaceship VALUES (‘falcon’, 15,
‘2040-04-16’);
• Add a few more records to your spaceship table
Note: you must enter values in the same order you used
during creation of the table
Read
• To read data from your database, one or more
tables must be queried
• The SELECT statement is used to perform queries
=> SELECT * FROM spaceship;
Read
• The * is a shorthand for “all columns”
• The same result could be achieved with:
=> SELECT nickname, crew_size, commission_date
FROM spaceship;
Read
• Queries can be ordered by adding ORDER BY
[column] to the end of your query
=> SELECT * FROM spaceship ORDER BY
nickname;
=> SELECT * FROM spaceship ORDER BY
commission_date;
Read
• Queries can be “qualified” by adding a WHERE
clause that specifies which rows are wanted
=> SELECT * FROM spaceship WHERE
commission_date > ‘2030-04-16’;
=> SELECT * FROM spaceship WHERE nickname =
‘falcon’;
=> SELECT * FROM spaceship WHERE crew_size >
5;
Update
• Rows can be updated using the UPDATE
command
• Update row(s) matching WHERE clause
=> UPDATE spaceship SET nickname = ‘eagle’
WHERE nickname = ‘falcon’;
• Careful, default updates all rows!
=> UPDATE spaceship SET crew_size = 20;
Destroy
• Rows can be destroyed using the DELETE
command
• Delete row(s) matching WHERE clause
=> DELETE from spaceship WHERE nickname =
‘falcon’;
• Careful, default deletes all rows!
=> DELETE from spaceship;
Congratulations!
• Now you know how to CRUD a PostgreSQL
database!
Digging Deeper…
• Joins between tables
• Transactions
But First…
• Install sample database that we can run some
joins/queries on
• https://code.google.com/p/northwindextended/down
loads/detail?name=northwind.postgre.sql
But First…
$ createdb northwind
$ psql northwind < northwind.postgre.sql
$ psql northwind
But First…
• Lets do a little exploration:
=> dt
=> d+ orders
=> d+ customers
Joins - Inner Join
• SQL inner join is the most common type of join
• Used to combine rows from two or more tables,
based on a common field between them
Joins - Inner Join
• Which company placed each order?
• Return the OrderID, CustomerID, and
CompanyName for each order
• Using an Inner Join we can join the orders table
with the customers table, using the CustomerID
=> SELECT “OrderID”, orders.”CustomerID’, “CompanyName”
FROM orders
INNER JOIN customers
ON orders.”CustomerID”=customers.”CustomerID”;
Joins - Inner Join
• What products were ordered, and what were their
prices?
• Return the ProductID, UnitPrice, and ProductName for
each item of a given order
• Using an Inner Join we can join the order_details table
with the products table
=> SELECT order_details.”ProductID”, ”UnitPrice”, “ProductName”
FROM order_details
INNER JOIN products
ON order_details.”ProductID”=products.”ProductID”
WHERE “OrderID” = 10248;
Joins - Left Outer Join
• The LEFT OUTER JOIN keyword returns all rows
from the left table (table1), with the matching rows
in the right table (table2). The result is NULL in the
right side when there is no match.
Joins - Left Outer Join
• “Let me see a list of all of our customers, and any
orders they have made”
• Need to return the CompanyName and associated
OrderID (if any)
• Using a Left Outer Join we can join the orders table
with the customers table
=> SELECT customers."CompanyName", orders.”OrderID"
FROM customers
LEFT OUTER JOIN orders
ON customers."CustomerID"=orders."CustomerID"
ORDER BY customers."CompanyName";
Joins - Right Outer Join
• The RIGHT JOIN keyword returns all rows from the
right table (table2), with the matching rows in the
left table (table1). The result is NULL in the left side
when there is no match.
Joins - Full Outer Join
• The FULL OUTER JOIN keyword returns all rows
from the left table (table1) and from the right table
(table2).The FULL OUTER JOIN keyword
combines the result of both LEFT and RIGHT joins.
Transactions
• “A transaction is a unit of work that is performed against a database.
Transactions are units or sequences of work accomplished in a logical
order, whether in a manual fashion by a user or automatically by some
sort of a database program.”
• “You use transactions when the set of database operations you are
making needs to be atomic. That is - they all need to succeed or fail.
Nothing in between.” http://stackoverflow.com/questions/9317866/when-to-use-transactions-in-sql-server
• Examples:
• Money transfer
• Order fulfillment
• Can you think of any others?
Joel Brewer
@jahbrewski
brewerdigital.com
joel@brewerdigital.com

More Related Content

What's hot (20)

[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
Equnix Business Solutions
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
botsplash.com
 
Migration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLMigration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQL
PGConf APAC
 
Working with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDB
ScaleGrid.io
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)
Noriyoshi Shinoda
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
Jaya Naresh Kovela
 
MongoDB vs. Postgres Benchmarks
MongoDB vs. Postgres Benchmarks MongoDB vs. Postgres Benchmarks
MongoDB vs. Postgres Benchmarks
EDB
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
Installation guide for mysql in windows
Installation guide for mysql in windowsInstallation guide for mysql in windows
Installation guide for mysql in windows
sharavanakumar10
 
Sq lite database
Sq lite databaseSq lite database
Sq lite database
AYESHA JAVED
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
Reuven Lerner
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
EDB
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
 
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교
Woo Yeong Choi
 
Modeling Data and Queries for Wide Column NoSQL
Modeling Data and Queries for Wide Column NoSQLModeling Data and Queries for Wide Column NoSQL
Modeling Data and Queries for Wide Column NoSQL
ScyllaDB
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
Equnix Business Solutions
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
botsplash.com
 
Migration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLMigration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQL
PGConf APAC
 
Working with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDBWorking with JSON Data in PostgreSQL vs. MongoDB
Working with JSON Data in PostgreSQL vs. MongoDB
ScaleGrid.io
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)
Noriyoshi Shinoda
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
MongoDB vs. Postgres Benchmarks
MongoDB vs. Postgres Benchmarks MongoDB vs. Postgres Benchmarks
MongoDB vs. Postgres Benchmarks
EDB
 
Installation guide for mysql in windows
Installation guide for mysql in windowsInstallation guide for mysql in windows
Installation guide for mysql in windows
sharavanakumar10
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
Ankit Rai
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
EDB
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
 
mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교
Woo Yeong Choi
 
Modeling Data and Queries for Wide Column NoSQL
Modeling Data and Queries for Wide Column NoSQLModeling Data and Queries for Wide Column NoSQL
Modeling Data and Queries for Wide Column NoSQL
ScyllaDB
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 

Viewers also liked (6)

certificate
certificatecertificate
certificate
Ivan Chernoff
 
Participant Schedule copy
Participant Schedule  copyParticipant Schedule  copy
Participant Schedule copy
Emily Hanna
 
La hora en Lengua Española
La hora en Lengua EspañolaLa hora en Lengua Española
La hora en Lengua Española
Elaine Campideli Hoyos
 
Electronic spectra
Electronic spectraElectronic spectra
Electronic spectra
mohammed rida
 
Requirements engineering in the rational unified process
Requirements engineering in the rational unified processRequirements engineering in the rational unified process
Requirements engineering in the rational unified process
Jorge Baque
 
Participant Schedule copy
Participant Schedule  copyParticipant Schedule  copy
Participant Schedule copy
Emily Hanna
 
Requirements engineering in the rational unified process
Requirements engineering in the rational unified processRequirements engineering in the rational unified process
Requirements engineering in the rational unified process
Jorge Baque
 
Ad

Similar to Introduction to PostgreSQL (20)

SQL_Part1
SQL_Part1SQL_Part1
SQL_Part1
Rick Perry
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
Sql Server 2000
Sql Server 2000Sql Server 2000
Sql Server 2000
Om Vikram Thapa
 
Practical Tutorial about the PostgreSQL Database
Practical Tutorial about the PostgreSQL DatabasePractical Tutorial about the PostgreSQL Database
Practical Tutorial about the PostgreSQL Database
sistemashcp
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
sagaroceanic11
 
10-Joins, views, and subqueries.pptx
10-Joins, views, and subqueries.pptx10-Joins, views, and subqueries.pptx
10-Joins, views, and subqueries.pptx
MAHIN33
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
Green plum培训材料
Green plum培训材料Green plum培训材料
Green plum培训材料
锐 张
 
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptxChjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
MhmdMk10
 
How to leave the ORM at home and write SQL
How to leave the ORM at home and write SQLHow to leave the ORM at home and write SQL
How to leave the ORM at home and write SQL
MariaDB plc
 
98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt
HastavaramDineshKuma
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
Abdul Rahman Sherzad
 
sql_bootcamp.pdf
sql_bootcamp.pdfsql_bootcamp.pdf
sql_bootcamp.pdf
John McClane
 
Modern sql
Modern sqlModern sql
Modern sql
Elizabeth Smith
 
Unit4_Lecture-sql.ppt and data science relate
Unit4_Lecture-sql.ppt and data science relateUnit4_Lecture-sql.ppt and data science relate
Unit4_Lecture-sql.ppt and data science relate
umang2782love
 
Meet the-other-elephant
Meet the-other-elephantMeet the-other-elephant
Meet the-other-elephant
Stefanie Janine Stölting
 
Golden Hammer - Shawn Oden
Golden Hammer - Shawn OdenGolden Hammer - Shawn Oden
Golden Hammer - Shawn Oden
Ortus Solutions, Corp
 
SQL-01-Basics.pptx
SQL-01-Basics.pptxSQL-01-Basics.pptx
SQL-01-Basics.pptx
joeveller
 
PostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The FuturePostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The Future
Aaron Thul
 
Database Overview
Database OverviewDatabase Overview
Database Overview
Livares Technologies Pvt Ltd
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
Practical Tutorial about the PostgreSQL Database
Practical Tutorial about the PostgreSQL DatabasePractical Tutorial about the PostgreSQL Database
Practical Tutorial about the PostgreSQL Database
sistemashcp
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
sagaroceanic11
 
10-Joins, views, and subqueries.pptx
10-Joins, views, and subqueries.pptx10-Joins, views, and subqueries.pptx
10-Joins, views, and subqueries.pptx
MAHIN33
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
Green plum培训材料
Green plum培训材料Green plum培训材料
Green plum培训材料
锐 张
 
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptxChjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
MhmdMk10
 
How to leave the ORM at home and write SQL
How to leave the ORM at home and write SQLHow to leave the ORM at home and write SQL
How to leave the ORM at home and write SQL
MariaDB plc
 
98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt
HastavaramDineshKuma
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
Abdul Rahman Sherzad
 
Unit4_Lecture-sql.ppt and data science relate
Unit4_Lecture-sql.ppt and data science relateUnit4_Lecture-sql.ppt and data science relate
Unit4_Lecture-sql.ppt and data science relate
umang2782love
 
SQL-01-Basics.pptx
SQL-01-Basics.pptxSQL-01-Basics.pptx
SQL-01-Basics.pptx
joeveller
 
PostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The FuturePostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The Future
Aaron Thul
 
Ad

Recently uploaded (20)

Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 

Introduction to PostgreSQL

  • 2. • Introduction to databases • Introduction to PostgreSQL • CRUD • Create • Read/query • Update • Destroy • Joins Overview
  • 3. What’s a database? • A database stores data! • It is a collection of information that is organized so that it can be easily accessed, managed, and updated
  • 4. Why do I care? • If you’re building a web application, you’re going to have data to store • What data do these websites store? • Facebook (users, profiles, groups, events, businesses) • Twitter (users, tweets) • CNN (articles, comments)
  • 5. What’s PostgreSQL? • PostgreSQL (“post-gress-Q-L”) is an open source object-relational database system • Open source = free! • Object - some object-oriented paradigms are natively supported, such as objects, classes, and inheritance • Relational - database is structured to recognize relations among stored items of information
  • 6. Let’s make a database $ createdb testdb $ psql testdb => SELECT version(); Note: to exit psql just type “q”
  • 7. Let’s make a table => CREATE TABLE spaceship ( nickname varchar(35), crew_size int, commission_date date );
  • 8. CRUD • CRUD (create, read, update, delete) are the four basic functions you perform on a database
  • 9. Create • Examples: • Creating a new account on Facebook • Posting a picture on Instagram • Creating a new tweet on Twitter
  • 10. Read • Examples: • Browsing your Facebook timeline • Looking at pictures on Instagram • Reading the latest article on CNN
  • 11. Update • Examples: • Changing your password • Editing a comment • Changing your relationship status on Facebook
  • 12. Destroy • Examples: • Deleting a picture on Facebook (well, maybe…) • Deleting a tweet on Twitter • Unfriending somebody on Facebook
  • 13. Create • SQL uses the INSERT statement to create a new row => INSERT INTO spaceship VALUES (‘falcon’, 15, ‘2040-04-16’); • Add a few more records to your spaceship table Note: you must enter values in the same order you used during creation of the table
  • 14. Read • To read data from your database, one or more tables must be queried • The SELECT statement is used to perform queries => SELECT * FROM spaceship;
  • 15. Read • The * is a shorthand for “all columns” • The same result could be achieved with: => SELECT nickname, crew_size, commission_date FROM spaceship;
  • 16. Read • Queries can be ordered by adding ORDER BY [column] to the end of your query => SELECT * FROM spaceship ORDER BY nickname; => SELECT * FROM spaceship ORDER BY commission_date;
  • 17. Read • Queries can be “qualified” by adding a WHERE clause that specifies which rows are wanted => SELECT * FROM spaceship WHERE commission_date > ‘2030-04-16’; => SELECT * FROM spaceship WHERE nickname = ‘falcon’; => SELECT * FROM spaceship WHERE crew_size > 5;
  • 18. Update • Rows can be updated using the UPDATE command • Update row(s) matching WHERE clause => UPDATE spaceship SET nickname = ‘eagle’ WHERE nickname = ‘falcon’; • Careful, default updates all rows! => UPDATE spaceship SET crew_size = 20;
  • 19. Destroy • Rows can be destroyed using the DELETE command • Delete row(s) matching WHERE clause => DELETE from spaceship WHERE nickname = ‘falcon’; • Careful, default deletes all rows! => DELETE from spaceship;
  • 20. Congratulations! • Now you know how to CRUD a PostgreSQL database!
  • 21. Digging Deeper… • Joins between tables • Transactions
  • 22. But First… • Install sample database that we can run some joins/queries on • https://code.google.com/p/northwindextended/down loads/detail?name=northwind.postgre.sql
  • 23. But First… $ createdb northwind $ psql northwind < northwind.postgre.sql $ psql northwind
  • 24. But First… • Lets do a little exploration: => dt => d+ orders => d+ customers
  • 25. Joins - Inner Join • SQL inner join is the most common type of join • Used to combine rows from two or more tables, based on a common field between them
  • 26. Joins - Inner Join • Which company placed each order? • Return the OrderID, CustomerID, and CompanyName for each order • Using an Inner Join we can join the orders table with the customers table, using the CustomerID => SELECT “OrderID”, orders.”CustomerID’, “CompanyName” FROM orders INNER JOIN customers ON orders.”CustomerID”=customers.”CustomerID”;
  • 27. Joins - Inner Join • What products were ordered, and what were their prices? • Return the ProductID, UnitPrice, and ProductName for each item of a given order • Using an Inner Join we can join the order_details table with the products table => SELECT order_details.”ProductID”, ”UnitPrice”, “ProductName” FROM order_details INNER JOIN products ON order_details.”ProductID”=products.”ProductID” WHERE “OrderID” = 10248;
  • 28. Joins - Left Outer Join • The LEFT OUTER JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.
  • 29. Joins - Left Outer Join • “Let me see a list of all of our customers, and any orders they have made” • Need to return the CompanyName and associated OrderID (if any) • Using a Left Outer Join we can join the orders table with the customers table => SELECT customers."CompanyName", orders.”OrderID" FROM customers LEFT OUTER JOIN orders ON customers."CustomerID"=orders."CustomerID" ORDER BY customers."CompanyName";
  • 30. Joins - Right Outer Join • The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.
  • 31. Joins - Full Outer Join • The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2).The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.
  • 32. Transactions • “A transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order, whether in a manual fashion by a user or automatically by some sort of a database program.” • “You use transactions when the set of database operations you are making needs to be atomic. That is - they all need to succeed or fail. Nothing in between.” http://stackoverflow.com/questions/9317866/when-to-use-transactions-in-sql-server • Examples: • Money transfer • Order fulfillment • Can you think of any others?