SlideShare a Scribd company logo
Rapid POSTGRESQL
learning, PART-5
BY: ALI MASUDIANPOUR MASUD.AMP@GMAIL.COM
RAPID POSTGRESQL LEARNING. 1
Transactions
◦ Transactions are a group of SQL commands
◦ These commands will be group together as an operation
◦ Transactions are supposed to be ACID, but what does that mean?
◦ ACID: Atomicity, Consistency, Isolation, Durability
◦ ATOMICITY
◦ All or nothing
◦ All of the operations must be succeed or all fails. In other word if one command fails other will fail too
◦ CONSYSTENCY
◦ Means that any transaction should take the system from one consistency o another
◦ In other words, only valid changes to the data will take a place
◦ ISOLATION
◦ Any pear of transactions should not be effecting the same row at once
◦ DURABILITY
◦ Once the transaction is committed, its result will not be lost forever
RAPID POSTGRESQL LEARNING. 2
Transactions
◦ Working with transactions (KEYWORDS)
◦ To begin transaction:
◦ BEGIN
◦ To end transaction
◦ COMMIT
◦ To cancel transaction
◦ ROLLBACK
◦ Example
◦ BEGIN;
SELECT * FROM [table name]
COMMIT;
◦ Control Transactions
◦ It is possible to control the commit in transactions using SAVEPOINT
RAPID POSTGRESQL LEARNING. 3
Save points
◦ Save points allow us to commit part of transaction and discard other parts
◦ How to use SAVE POINT:
◦ BEGIN
UPDATE x SET y=20 WHERE 1
SAVEPOINT [save point name]
UPDATE z SET a=14 WHERE 1
SOLLBACK TO SAVEPOINT [save point name]
COMMIT;
◦ Everything before save point will be committed and everything after save point will be discarded
◦ Destroy SAVE POINT
◦ To destroy a save point we use RELEASE
◦ RELEASE SAVEPOINT [save point name]
◦ After deletion of save point if we try to ROLLBACK TO SAVEPOINT [save point name] it will show an error!
RAPID POSTGRESQL LEARNING. 4
DEADLOCKS
◦ A deadlock happens when two or more transactions hold locks at other transactions at once
◦ As we saw before, same operations on same rows in transaction can not be happen
◦ If we do, it will be wait until first transaction done.
◦ DEADLOCK
◦ For instance: if we start a transaction one[1] and after that start the transaction two[2] and in transaction two[2] we write a
command that will be wait for transaction one[1] to be done and after that we do the same in transaction one[1] deadlock will be
happen.
◦ At this moment we have to ROLLBACK
◦ If we try to COMMIT, it will automatically ROLLBACK
RAPID POSTGRESQL LEARNING. 5
System Columns
◦ Columns that are added to the table automatically called System Columns
◦ List of System Columns
◦ XMIN
◦ Transaction id of the inserting transaction for this row version. It also can be update
◦ ROW VERSION
◦ Is an individual state of a row. Every time we update the row, new row version will be generated
◦ XMAX
◦ Transaction id of deletion row
◦ CTID
◦ Physical location of the row version in the table
◦ OIDS
◦ Table object id
◦ If we want to use OIDS, we should indicate in on the table creation time
◦ CREATE TABLE … WITH OIDS;
◦ Examples:
◦ SELECT oid, tableoid, xmax, xmin FROM [table name]
RAPID POSTGRESQL LEARNING. 6
Alternation in tables and columns
◦ Change data type of column
◦ ALTER [table name] ALTER COLUMN [column name] TYPE [new type]
◦ Change default value of column
◦ ALTER TABLE [table name] ALTER COLUMN [column name] SET DEFAULT [value];
◦ Unset default value
◦ ALTER TABLE [table name] ALTER COLUMN [column name] SET DEFAULT NULL
◦ ALTER TABLE [table name] ALTER COLUMN [column name] DROP DEFAULT
◦ Add Column
◦ ALTER TABLE [table name] ADD COLUMN [column name] [column type]
◦ ALTER TABLE [table name] ADD COLUMN [column name] [column type] NOT NULL DEFAULT [value]
◦ Remove Column
◦ ALTER TABLE [table name] DROP COLUMN [column name]
◦ Every data and constraints will be deleted
◦ If it has a reference column, we must use CASCADE to remove
RAPID POSTGRESQL LEARNING. 7
Alternation in tables and columns
◦ Add Constraint
◦ CHECK
◦ ALTER TABLE [table name] ADD CONSTRAINT [constraint name] CHECK([condition])
◦ UNIQUE
◦ ALTER TABLE [table name] ADD CONSTRAINT [constraint name] UNIQUE ([column name])
◦ FOREIGN KEY
◦ ALTER TABLE [table name] ADD FOREIGN KEY [foreign key name] REFERENCES [reference table name]([reference table column
name])
◦ NOT NULL
◦ ALTER TABLE [table name] ALTER COLUMN [column name] SET NOT NULL
◦ All of the values must satisfy constraints to be done
◦ For instance we have a column that holds null value, now if we set null constraint it will generate an error, because it has a null
value.
RAPID POSTGRESQL LEARNING. 8
Alternation in tables and columns
◦ Remove Constraint
◦ ALTER TABLE [table name] DROP CONSTRAINT [constraint name]
◦ If it uses a reference we should use CASCADE
◦ Remove Not Null Constraint
◦ ALTER TABLE [table name] ALTER COLUMN [column name] DROP NOT NULL
◦ Rename Column name
◦ ALTER TABLE [table name] RENAME COLUMN [column name] TO [new column name]
◦ Rename Table name
◦ ALTER TABLE [table name] RENAME TO [new table name]
RAPID POSTGRESQL LEARNING. 9
Logical Operators
◦ 3 types of Logical operators
◦ AND
◦ Will be true if both left and right operands are true
◦ OR
◦ Will be true if one of the operands is true, otherwise it will be false
◦ NOT
◦ Will be false if the operand is true and will be true if the operand is false
◦ AND / OR has 2 right and left operand
◦ NOT has one operand
◦ Examples:
◦ SELECT * FROM tableTest WHERE x>12 AND y<10
◦ SELECT * FROM tableTest WHERE x>12 OR y<10
◦ SELECT * FROM tableTest WHERE NOT x>12
RAPID POSTGRESQL LEARNING. 10
Comparison Operands
◦ They are
◦ <
◦ <=
◦ >
◦ >=
◦ =
◦ !
◦ Examples
◦ SELECT * FROM testable WHERE column1!=3600
◦ SELECT * FROM testable WHERE column1=3600
◦ SELECT * FROM testable WHERE column1>=3600
◦ SELECT * FROM testable WHERE column1<=3600
◦ SELECT * FROM testable WHERE column1>3600
◦ SELECT * FROM testable WHERE column1<3600
RAPID POSTGRESQL LEARNING. 11
Between
◦ Between
◦ To run a condition between a range
◦ Example:
◦ SELECT * FROM employee WHERE salary BETWEEN 2000 AND 9000
◦ The less value should be take place in left side of AND operator
◦ SYMETRIC BETWEEN
◦ In this case there would be no force to left operand be greater than right operand
◦ Example
◦ SELECT * FROM employee WHERE salary BETWEEN SYMETRIC 9000 AND 2000
◦ NOT BETWEEN
◦ SELECT * FROM employee WHERE salary NOT BETWEEN 5000 AND 6000
RAPID POSTGRESQL LEARNING. 12
IS NULL/ IS NOT NULL
◦ SELECT * FROM employee WHERE salary IS NULL
◦ SELECT * FROM employee WHERE salary IS NOT NULL
◦ SELECT * FROM employee WHERE (salary>3000) IS TRUE
◦ SELECT * FROM employee WHERE (salary>3000) IS NOT TRUE
◦ SELECT * FROM employee WHERE (salary>3000) IS FALSE
◦ SELECT * FROM employee WHERE (salary>3000) IS NOT FALSE
◦ SELECT * FROM employee WHERE (salary>3000) IS UNKNOWN
◦ SELECT * FROM employee WHERE (salary>3000) IS NOT UNKNOWN
RAPID POSTGRESQL LEARNING. 13
Mathematical Operators
◦ Addition
◦ SELECT 7+3
◦ Subtraction
◦ SELECT 7-3
◦ Multiplication
◦ SELECT 7*3
◦ Division
◦ SELECT 7/3
◦ Modulo
◦ SELECT 7%3
◦ Exponentiation
◦ SELECT 7^3
◦ Square Root
◦ SELECT |/4
◦ Cube root
◦ SELECT ||/8
◦ Factorial
◦ SELECT 7! AD ‘Factorial’
RAPID POSTGRESQL LEARNING. 14
Mathematical Functions
◦ Natural Logarithm
◦ SELECT ln(4)
◦ Base 10 logarithm
◦ SELECT log(8)
◦ PI Constant
◦ SELECT pi() AS ‘PI’
◦ Power
◦ SELECT power(2,3)
◦ Round
◦ SELECT round(2.888888)
◦ Truncate
◦ SELECT TRUNC(2.567,2) // truncate to 2 decimal points. Result : 2.56
◦ SELECT TRUNC(2.567) // result: 2
RAPID POSTGRESQL LEARNING. 15
Mathematical Functions
◦ Floor
◦ Largest integer not greater than entered value
◦ SELECT FLOOR(4.5)
◦ Result: 4
◦ CEIL
◦ Smallest integer not less that entered value
◦ SELECT CEIL(4.5)
◦ Result: 5
◦ Absolute value
◦ SELECT abs(-4.88)
◦ Division
◦ SELECT DIV(4,7)
◦ Modulo
◦ SELECT MOD(4,5)
◦ Square root
◦ SELECT SQRT(25)
◦ Cube Root
◦ SELECT CBRT(45)
RAPID POSTGRESQL LEARNING. 16
END OF PART 4
End of Part 4
◦ In part 5 we will discuss about:
◦ STRING FUNCTIONS AND OPERATIONS
◦ DATE AND TIME
◦ SEQUENCES
◦ CONDITIONAL EXPRESSIONS
◦ SCHEMA and PRIVILEGES
◦ INDEXES
RAPID POSTGRESQL LEARNING. 17

More Related Content

What's hot

ActiveRecord is Rotting Your Brian
ActiveRecord is Rotting Your BrianActiveRecord is Rotting Your Brian
ActiveRecord is Rotting Your BrianEthan Gunderson
 
MySQL Views
MySQL ViewsMySQL Views
Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql database
Kimera Richard
 
Investigation of Transactions in Cassandra
Investigation of Transactions in CassandraInvestigation of Transactions in Cassandra
Investigation of Transactions in Cassandra
datastaxjp
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
thewebsacademy
 
Specs2
Specs2Specs2
Sql triggers
Sql triggersSql triggers
Sql triggers
Chandan Banerjee
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkKaniska Mandal
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
Arun Sial
 
Stored procedure
Stored procedureStored procedure
Stored procedure
Deepak Sharma
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
OSSCube
 
บทที่3
บทที่3บทที่3
บทที่3Palm Unnop
 
Introduction to type classes
Introduction to type classesIntroduction to type classes
Introduction to type classes
Pawel Szulc
 
Introduction to type classes in 30 min
Introduction to type classes in 30 minIntroduction to type classes in 30 min
Introduction to type classes in 30 min
Pawel Szulc
 
Triggers
TriggersTriggers
Triggers
Pooja Dixit
 
OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)
Jason Huynh
 
KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7
phuphax
 
Trigger in DBMS
Trigger in DBMSTrigger in DBMS
Trigger in DBMS
A. S. M. Shafi
 

What's hot (20)

ActiveRecord is Rotting Your Brian
ActiveRecord is Rotting Your BrianActiveRecord is Rotting Your Brian
ActiveRecord is Rotting Your Brian
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
MySQL Views
MySQL ViewsMySQL Views
MySQL Views
 
Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql database
 
Investigation of Transactions in Cassandra
Investigation of Transactions in CassandraInvestigation of Transactions in Cassandra
Investigation of Transactions in Cassandra
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 
Specs2
Specs2Specs2
Specs2
 
Sql triggers
Sql triggersSql triggers
Sql triggers
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
 
บทที่3
บทที่3บทที่3
บทที่3
 
Introduction to type classes
Introduction to type classesIntroduction to type classes
Introduction to type classes
 
Introduction to type classes in 30 min
Introduction to type classes in 30 minIntroduction to type classes in 30 min
Introduction to type classes in 30 min
 
Triggers
TriggersTriggers
Triggers
 
OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)
 
KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 6/7
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Trigger in DBMS
Trigger in DBMSTrigger in DBMS
Trigger in DBMS
 

Viewers also liked

Rapid postgresql learning, part 3
Rapid postgresql learning, part 3Rapid postgresql learning, part 3
Rapid postgresql learning, part 3Ali MasudianPour
 
Prak2-Wireshark
Prak2-WiresharkPrak2-Wireshark
Prak2-Wireshark
Putra Wanda
 
Rapid postgresql learning, part 2
Rapid postgresql learning, part 2Rapid postgresql learning, part 2
Rapid postgresql learning, part 2Ali MasudianPour
 
Prak4-Perintah Dasar Linux
Prak4-Perintah Dasar LinuxPrak4-Perintah Dasar Linux
Prak4-Perintah Dasar Linux
Putra Wanda
 
Postgres rules
Postgres rulesPostgres rules
Postgres rules
gisborne
 
Prak5-Pengenalan Mikrotik
Prak5-Pengenalan MikrotikPrak5-Pengenalan Mikrotik
Prak5-Pengenalan Mikrotik
Putra Wanda
 
Tutorial Postgre SQL
Tutorial Postgre SQLTutorial Postgre SQL
Tutorial Postgre SQL
Hari Setiaji
 
Rapid postgresql learning, part 1
Rapid postgresql learning, part 1Rapid postgresql learning, part 1
Rapid postgresql learning, part 1Ali MasudianPour
 
Prak9-Bandwith Limiter
Prak9-Bandwith LimiterPrak9-Bandwith Limiter
Prak9-Bandwith Limiter
Putra Wanda
 

Viewers also liked (9)

Rapid postgresql learning, part 3
Rapid postgresql learning, part 3Rapid postgresql learning, part 3
Rapid postgresql learning, part 3
 
Prak2-Wireshark
Prak2-WiresharkPrak2-Wireshark
Prak2-Wireshark
 
Rapid postgresql learning, part 2
Rapid postgresql learning, part 2Rapid postgresql learning, part 2
Rapid postgresql learning, part 2
 
Prak4-Perintah Dasar Linux
Prak4-Perintah Dasar LinuxPrak4-Perintah Dasar Linux
Prak4-Perintah Dasar Linux
 
Postgres rules
Postgres rulesPostgres rules
Postgres rules
 
Prak5-Pengenalan Mikrotik
Prak5-Pengenalan MikrotikPrak5-Pengenalan Mikrotik
Prak5-Pengenalan Mikrotik
 
Tutorial Postgre SQL
Tutorial Postgre SQLTutorial Postgre SQL
Tutorial Postgre SQL
 
Rapid postgresql learning, part 1
Rapid postgresql learning, part 1Rapid postgresql learning, part 1
Rapid postgresql learning, part 1
 
Prak9-Bandwith Limiter
Prak9-Bandwith LimiterPrak9-Bandwith Limiter
Prak9-Bandwith Limiter
 

Similar to Rapid postgresql learning, part 4

MySQL Pro
MySQL ProMySQL Pro
Performance tuning
Performance tuningPerformance tuning
Performance tuning
ami111
 
triggers.pptx
triggers.pptxtriggers.pptx
triggers.pptx
Zaid227349
 
IR SQLite Session #3
IR SQLite Session #3IR SQLite Session #3
IR SQLite Session #3
InfoRepos Technologies
 
8. sql
8. sql8. sql
8. sql
khoahuy82
 
SQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdfSQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdf
Madhusha15
 
Week 7 Slides - Advanced Queries - SQL Functions (1).pptx
Week 7 Slides - Advanced Queries - SQL Functions (1).pptxWeek 7 Slides - Advanced Queries - SQL Functions (1).pptx
Week 7 Slides - Advanced Queries - SQL Functions (1).pptx
SadhanaKumari43
 
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
 
Green plum培训材料
Green plum培训材料Green plum培训材料
Green plum培训材料锐 张
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
srijanani2030
 
STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGESTRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 

Similar to Rapid postgresql learning, part 4 (20)

Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
MySQL Pro
MySQL ProMySQL Pro
MySQL Pro
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
 
triggers.pptx
triggers.pptxtriggers.pptx
triggers.pptx
 
Sql transacation
Sql transacationSql transacation
Sql transacation
 
IR SQLite Session #3
IR SQLite Session #3IR SQLite Session #3
IR SQLite Session #3
 
8. sql
8. sql8. sql
8. sql
 
SQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdfSQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdf
 
Sql
SqlSql
Sql
 
Sql
SqlSql
Sql
 
SQL
SQLSQL
SQL
 
Week 7 Slides - Advanced Queries - SQL Functions (1).pptx
Week 7 Slides - Advanced Queries - SQL Functions (1).pptxWeek 7 Slides - Advanced Queries - SQL Functions (1).pptx
Week 7 Slides - Advanced Queries - SQL Functions (1).pptx
 
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
 
Green plum培训材料
Green plum培训材料Green plum培训材料
Green plum培训材料
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
 
STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGESTRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE
 
Module04
Module04Module04
Module04
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Rapid postgresql learning, part 4

  • 1. Rapid POSTGRESQL learning, PART-5 BY: ALI MASUDIANPOUR MASUD.AMP@GMAIL.COM RAPID POSTGRESQL LEARNING. 1
  • 2. Transactions ◦ Transactions are a group of SQL commands ◦ These commands will be group together as an operation ◦ Transactions are supposed to be ACID, but what does that mean? ◦ ACID: Atomicity, Consistency, Isolation, Durability ◦ ATOMICITY ◦ All or nothing ◦ All of the operations must be succeed or all fails. In other word if one command fails other will fail too ◦ CONSYSTENCY ◦ Means that any transaction should take the system from one consistency o another ◦ In other words, only valid changes to the data will take a place ◦ ISOLATION ◦ Any pear of transactions should not be effecting the same row at once ◦ DURABILITY ◦ Once the transaction is committed, its result will not be lost forever RAPID POSTGRESQL LEARNING. 2
  • 3. Transactions ◦ Working with transactions (KEYWORDS) ◦ To begin transaction: ◦ BEGIN ◦ To end transaction ◦ COMMIT ◦ To cancel transaction ◦ ROLLBACK ◦ Example ◦ BEGIN; SELECT * FROM [table name] COMMIT; ◦ Control Transactions ◦ It is possible to control the commit in transactions using SAVEPOINT RAPID POSTGRESQL LEARNING. 3
  • 4. Save points ◦ Save points allow us to commit part of transaction and discard other parts ◦ How to use SAVE POINT: ◦ BEGIN UPDATE x SET y=20 WHERE 1 SAVEPOINT [save point name] UPDATE z SET a=14 WHERE 1 SOLLBACK TO SAVEPOINT [save point name] COMMIT; ◦ Everything before save point will be committed and everything after save point will be discarded ◦ Destroy SAVE POINT ◦ To destroy a save point we use RELEASE ◦ RELEASE SAVEPOINT [save point name] ◦ After deletion of save point if we try to ROLLBACK TO SAVEPOINT [save point name] it will show an error! RAPID POSTGRESQL LEARNING. 4
  • 5. DEADLOCKS ◦ A deadlock happens when two or more transactions hold locks at other transactions at once ◦ As we saw before, same operations on same rows in transaction can not be happen ◦ If we do, it will be wait until first transaction done. ◦ DEADLOCK ◦ For instance: if we start a transaction one[1] and after that start the transaction two[2] and in transaction two[2] we write a command that will be wait for transaction one[1] to be done and after that we do the same in transaction one[1] deadlock will be happen. ◦ At this moment we have to ROLLBACK ◦ If we try to COMMIT, it will automatically ROLLBACK RAPID POSTGRESQL LEARNING. 5
  • 6. System Columns ◦ Columns that are added to the table automatically called System Columns ◦ List of System Columns ◦ XMIN ◦ Transaction id of the inserting transaction for this row version. It also can be update ◦ ROW VERSION ◦ Is an individual state of a row. Every time we update the row, new row version will be generated ◦ XMAX ◦ Transaction id of deletion row ◦ CTID ◦ Physical location of the row version in the table ◦ OIDS ◦ Table object id ◦ If we want to use OIDS, we should indicate in on the table creation time ◦ CREATE TABLE … WITH OIDS; ◦ Examples: ◦ SELECT oid, tableoid, xmax, xmin FROM [table name] RAPID POSTGRESQL LEARNING. 6
  • 7. Alternation in tables and columns ◦ Change data type of column ◦ ALTER [table name] ALTER COLUMN [column name] TYPE [new type] ◦ Change default value of column ◦ ALTER TABLE [table name] ALTER COLUMN [column name] SET DEFAULT [value]; ◦ Unset default value ◦ ALTER TABLE [table name] ALTER COLUMN [column name] SET DEFAULT NULL ◦ ALTER TABLE [table name] ALTER COLUMN [column name] DROP DEFAULT ◦ Add Column ◦ ALTER TABLE [table name] ADD COLUMN [column name] [column type] ◦ ALTER TABLE [table name] ADD COLUMN [column name] [column type] NOT NULL DEFAULT [value] ◦ Remove Column ◦ ALTER TABLE [table name] DROP COLUMN [column name] ◦ Every data and constraints will be deleted ◦ If it has a reference column, we must use CASCADE to remove RAPID POSTGRESQL LEARNING. 7
  • 8. Alternation in tables and columns ◦ Add Constraint ◦ CHECK ◦ ALTER TABLE [table name] ADD CONSTRAINT [constraint name] CHECK([condition]) ◦ UNIQUE ◦ ALTER TABLE [table name] ADD CONSTRAINT [constraint name] UNIQUE ([column name]) ◦ FOREIGN KEY ◦ ALTER TABLE [table name] ADD FOREIGN KEY [foreign key name] REFERENCES [reference table name]([reference table column name]) ◦ NOT NULL ◦ ALTER TABLE [table name] ALTER COLUMN [column name] SET NOT NULL ◦ All of the values must satisfy constraints to be done ◦ For instance we have a column that holds null value, now if we set null constraint it will generate an error, because it has a null value. RAPID POSTGRESQL LEARNING. 8
  • 9. Alternation in tables and columns ◦ Remove Constraint ◦ ALTER TABLE [table name] DROP CONSTRAINT [constraint name] ◦ If it uses a reference we should use CASCADE ◦ Remove Not Null Constraint ◦ ALTER TABLE [table name] ALTER COLUMN [column name] DROP NOT NULL ◦ Rename Column name ◦ ALTER TABLE [table name] RENAME COLUMN [column name] TO [new column name] ◦ Rename Table name ◦ ALTER TABLE [table name] RENAME TO [new table name] RAPID POSTGRESQL LEARNING. 9
  • 10. Logical Operators ◦ 3 types of Logical operators ◦ AND ◦ Will be true if both left and right operands are true ◦ OR ◦ Will be true if one of the operands is true, otherwise it will be false ◦ NOT ◦ Will be false if the operand is true and will be true if the operand is false ◦ AND / OR has 2 right and left operand ◦ NOT has one operand ◦ Examples: ◦ SELECT * FROM tableTest WHERE x>12 AND y<10 ◦ SELECT * FROM tableTest WHERE x>12 OR y<10 ◦ SELECT * FROM tableTest WHERE NOT x>12 RAPID POSTGRESQL LEARNING. 10
  • 11. Comparison Operands ◦ They are ◦ < ◦ <= ◦ > ◦ >= ◦ = ◦ ! ◦ Examples ◦ SELECT * FROM testable WHERE column1!=3600 ◦ SELECT * FROM testable WHERE column1=3600 ◦ SELECT * FROM testable WHERE column1>=3600 ◦ SELECT * FROM testable WHERE column1<=3600 ◦ SELECT * FROM testable WHERE column1>3600 ◦ SELECT * FROM testable WHERE column1<3600 RAPID POSTGRESQL LEARNING. 11
  • 12. Between ◦ Between ◦ To run a condition between a range ◦ Example: ◦ SELECT * FROM employee WHERE salary BETWEEN 2000 AND 9000 ◦ The less value should be take place in left side of AND operator ◦ SYMETRIC BETWEEN ◦ In this case there would be no force to left operand be greater than right operand ◦ Example ◦ SELECT * FROM employee WHERE salary BETWEEN SYMETRIC 9000 AND 2000 ◦ NOT BETWEEN ◦ SELECT * FROM employee WHERE salary NOT BETWEEN 5000 AND 6000 RAPID POSTGRESQL LEARNING. 12
  • 13. IS NULL/ IS NOT NULL ◦ SELECT * FROM employee WHERE salary IS NULL ◦ SELECT * FROM employee WHERE salary IS NOT NULL ◦ SELECT * FROM employee WHERE (salary>3000) IS TRUE ◦ SELECT * FROM employee WHERE (salary>3000) IS NOT TRUE ◦ SELECT * FROM employee WHERE (salary>3000) IS FALSE ◦ SELECT * FROM employee WHERE (salary>3000) IS NOT FALSE ◦ SELECT * FROM employee WHERE (salary>3000) IS UNKNOWN ◦ SELECT * FROM employee WHERE (salary>3000) IS NOT UNKNOWN RAPID POSTGRESQL LEARNING. 13
  • 14. Mathematical Operators ◦ Addition ◦ SELECT 7+3 ◦ Subtraction ◦ SELECT 7-3 ◦ Multiplication ◦ SELECT 7*3 ◦ Division ◦ SELECT 7/3 ◦ Modulo ◦ SELECT 7%3 ◦ Exponentiation ◦ SELECT 7^3 ◦ Square Root ◦ SELECT |/4 ◦ Cube root ◦ SELECT ||/8 ◦ Factorial ◦ SELECT 7! AD ‘Factorial’ RAPID POSTGRESQL LEARNING. 14
  • 15. Mathematical Functions ◦ Natural Logarithm ◦ SELECT ln(4) ◦ Base 10 logarithm ◦ SELECT log(8) ◦ PI Constant ◦ SELECT pi() AS ‘PI’ ◦ Power ◦ SELECT power(2,3) ◦ Round ◦ SELECT round(2.888888) ◦ Truncate ◦ SELECT TRUNC(2.567,2) // truncate to 2 decimal points. Result : 2.56 ◦ SELECT TRUNC(2.567) // result: 2 RAPID POSTGRESQL LEARNING. 15
  • 16. Mathematical Functions ◦ Floor ◦ Largest integer not greater than entered value ◦ SELECT FLOOR(4.5) ◦ Result: 4 ◦ CEIL ◦ Smallest integer not less that entered value ◦ SELECT CEIL(4.5) ◦ Result: 5 ◦ Absolute value ◦ SELECT abs(-4.88) ◦ Division ◦ SELECT DIV(4,7) ◦ Modulo ◦ SELECT MOD(4,5) ◦ Square root ◦ SELECT SQRT(25) ◦ Cube Root ◦ SELECT CBRT(45) RAPID POSTGRESQL LEARNING. 16
  • 17. END OF PART 4 End of Part 4 ◦ In part 5 we will discuss about: ◦ STRING FUNCTIONS AND OPERATIONS ◦ DATE AND TIME ◦ SEQUENCES ◦ CONDITIONAL EXPRESSIONS ◦ SCHEMA and PRIVILEGES ◦ INDEXES RAPID POSTGRESQL LEARNING. 17