5. History of PostgreSQL
• INGRES, Berkeley 1982
• POSTGRES, Berkeley 1985
• POSTGRES v1, 1989
• PostQUEL, 1990
•PostgreSQL 6.0 (1995)
• Initial release
•PostgreSQL 7.0 (2000)
• SQL92 compliance
•PostgreSQL 8.0 (2005)
• Multi-Platform support
• Analytical Function
support
•PostgreSQL 9.0 (2010)
• Built-in Replication
• JSON datatype support
6. Rule of Thumb
From Tom Kyte (Oracle Evangelist)
1. Use single SQL statement whenever
possible
2. Use PL/SQL or Stored Procedure
3. Use Java (or other programming
language)
4. Rethink why you want to do it
(refine your approach)
8. ChangeYour Mindset!
• Apa yang akan kalian lakukan jika mendapatkan tugas seperti di
bawah ini
• Tampilkan angka 1 sampai dengan 100, namun
setiap kelipatan 3 ubah angkanya menjadi kata
Rumah, setiap kelipatan 5 ubah angkanya menjadi
kata Sakit, dan setiap kelipatan 15 ubah angkanya
menjadi kata Rumah Sakit.
13. ChangeYour Mindset!
• Apa yang akan kalian lakukan jika diminta membuat output
seperti di bawah ini
Tabel A
ID Description
1 SUV
2 Sedan
3 Truk
4 Bus
5 MPV
Tabel B
A_ID Description
1 Toyota Fortuner
1 BMW X5
2 ToyotaVios
2 Honda City
5 Dahihatsu GranMax
ID Description Jumlah
1 SUV 2
2 Sedan 2
3 Truk 0
4 Bus 0
5 MPV 1
15. Common Table Expression
• Standard SQL feature
• Allows you to split a query statement into distinct
parts
• Results of each part will appear as a table
• More maintainable than subqueries
16. Hierarchical Queries
• Fixed depth hierarchical data can be solved using
simple JOINs
• CTE allows recursive query
• CTE can process data as hierarchical
• CTE can process arbitrarily deep hierarchies with
just one query
18. Aggregates and Window Functions
• GROUP BY lets you calculate aggregates of data over a single or
multiple columns in a result set.
• GROUP BY can only aggregate over a single grouping
• GROUP BY only return aggregated data, detail data is not
preserved
• Window functions make it possible
• Indicated by OVER Clause
• ROW_NUMBER() OVER()
• SUM() OVER()
• COUNT() OVER()
• MAX() OVER()
• MIN() OVER()
• AVG() OVER()
20. Pivoting data
• Sometimes it’s nice to be able to pivot data in a
properly normalized data model, so that repeating
groups of related entities are folded into parent
entity as columns.
• Pivoting is very useful reporting purposes and ad-
hoc queries.
• PostgreSQL can handle pivoting data using
• Subqueries and Arrays
• UsingCASE clause
22. Other Advanced PostgreSQL
• JSON built-in support
• Pattern matching. Regular expression matching is
supported
• Geolocation queries. PostGIS extension adds
comprehensive support for managing and querying
geospatial data
• Partitioning
• Replication