SlideShare uma empresa Scribd logo
1 de 33
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

Mais conteúdo relacionado

Mais procurados

Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresqlbotsplash.com
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
Webinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanWebinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanGabriele Bartolini
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HAharoonm
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...
PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...
PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...MinhLeNguyenAnh2
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuningelliando dias
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsCommand Prompt., Inc
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfJesmar Cannao'
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaPostgreSQL-Consulting
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres MonitoringDenish Patel
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용I Goo Lee
 
Patroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyAlexander Kukushkin
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxNeoClova
 
PostgreSQL Tutorial for Beginners | Edureka
PostgreSQL Tutorial for Beginners | EdurekaPostgreSQL Tutorial for Beginners | Edureka
PostgreSQL Tutorial for Beginners | EdurekaEdureka!
 
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLTop 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLJim Mlodgenski
 
MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바NeoClova
 
Escalabilidade horizontal com PostgreSQL e Pgpool II
Escalabilidade horizontal com PostgreSQL e Pgpool IIEscalabilidade horizontal com PostgreSQL e Pgpool II
Escalabilidade horizontal com PostgreSQL e Pgpool IIMatheus Espanhol
 

Mais procurados (20)

PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Webinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanWebinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with Barman
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...
PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...
PostgreSQL_ Up and Running_ A Practical Guide to the Advanced Open Source Dat...
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres Monitoring
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용
 
Patroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easy
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
 
PostgreSQL Tutorial for Beginners | Edureka
PostgreSQL Tutorial for Beginners | EdurekaPostgreSQL Tutorial for Beginners | Edureka
PostgreSQL Tutorial for Beginners | Edureka
 
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLTop 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
 
MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바MySQL Administrator 2021 - 네오클로바
MySQL Administrator 2021 - 네오클로바
 
Escalabilidade horizontal com PostgreSQL e Pgpool II
Escalabilidade horizontal com PostgreSQL e Pgpool IIEscalabilidade horizontal com PostgreSQL e Pgpool II
Escalabilidade horizontal com PostgreSQL e Pgpool II
 

Destaque

Participant Schedule copy
Participant Schedule  copyParticipant Schedule  copy
Participant Schedule copyEmily 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 processJorge Baque
 

Destaque (6)

certificate
certificatecertificate
certificate
 
Participant Schedule copy
Participant Schedule  copyParticipant Schedule  copy
Participant Schedule copy
 
La hora en Lengua Española
La hora en Lengua EspañolaLa hora en Lengua Española
La hora en Lengua Española
 
SWaM LOGO
SWaM LOGOSWaM LOGO
SWaM LOGO
 
Electronic spectra
Electronic spectraElectronic spectra
Electronic spectra
 
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
 

Semelhante a Introduction to PostgreSQL

SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Subhasis Nayak
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql Subhasis Nayak
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxYashaswiniSrinivasan1
 
Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Jennifer Berk
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sqlŁukasz Grala
 
Database Programming
Database ProgrammingDatabase Programming
Database ProgrammingHenry Osborne
 
Alasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User ManualAlasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User ManualAndrey Gershun
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptgourav kottawar
 
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)Michael Rys
 
PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databaseBarry Jones
 
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptxShshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx086ChintanPatel1
 
Tk2323 lecture 7 sql
Tk2323 lecture 7   sql Tk2323 lecture 7   sql
Tk2323 lecture 7 sql MengChun Lam
 

Semelhante a Introduction to PostgreSQL (20)

SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
Mentor Your Indexes
Mentor Your IndexesMentor Your Indexes
Mentor Your Indexes
 
Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)
 
SQL
SQLSQL
SQL
 
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql
 
Database Programming
Database ProgrammingDatabase Programming
Database Programming
 
Alasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User ManualAlasql JavaScript SQL Database Library: User Manual
Alasql JavaScript SQL Database Library: User Manual
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
 
PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty database
 
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptxShshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
 
Tk2323 lecture 7 sql
Tk2323 lecture 7   sql Tk2323 lecture 7   sql
Tk2323 lecture 7 sql
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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?