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)

Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
Jim Mlodgenski
 
Postgresql
PostgresqlPostgresql
Postgresql
NexThoughts Technologies
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
MYXPLAIN
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
PostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_CheatsheetPostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_Cheatsheet
Lucian Oprea
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
Karwin Software Solutions LLC
 
Built in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat GulecBuilt in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat Gulec
FIRAT GULEC
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
PgDay.Seoul
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
elliando dias
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinC* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
DataStax Academy
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
Open Source School
 
Sql server
Sql serverSql server
Sql server
Fajar Baskoro
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
botsplash.com
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
PgDay.Seoul
 
Basic oracle-database-administration
Basic oracle-database-administrationBasic oracle-database-administration
Basic oracle-database-administration
sreehari orienit
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
EDB
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
Amrit Kaur
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
jkeriaki
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
Jim Mlodgenski
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
MYXPLAIN
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
PostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_CheatsheetPostgreSQL High_Performance_Cheatsheet
PostgreSQL High_Performance_Cheatsheet
Lucian Oprea
 
Built in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat GulecBuilt in physical and logical replication in postgresql-Firat Gulec
Built in physical and logical replication in postgresql-Firat Gulec
FIRAT GULEC
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
PgDay.Seoul
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
elliando dias
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinC* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
DataStax Academy
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
botsplash.com
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
PgDay.Seoul
 
Basic oracle-database-administration
Basic oracle-database-administrationBasic oracle-database-administration
Basic oracle-database-administration
sreehari orienit
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
EDB
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
Amrit Kaur
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
jkeriaki
 

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)

Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
DevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical PodcastDevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical Podcast
Chris Wahl
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
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
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Scott M. Graffius
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
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
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
DevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical PodcastDevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical Podcast
Chris Wahl
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
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
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Scott M. Graffius
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
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
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 

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?