SlideShare a Scribd company logo
Text 
Tracking your Data Across the Fourth Dimension 
Wellington Waterloo Web Makers Meetup
“In physics, spacetime is any mathematical model 
that combines space and time into a single 
interwoven continuum.” 
–Wikipedia
Databases are Good at 
‘Now’ 
CRUD 
Create data 
Read data 
Update data 
Delete data
Bread and Butter Queries 
How many people work 
in department X? 
What’s the total amount 
paid in commissions by 
department? 
What was the top selling 
product in the last year?
The Fourth Dimension… 
Compare reporting 
relationships one month ago, 
today and in one months time 
Show me all changes made 
to this data over time 
As of one month ago, what 
did I believe to be the truth 
about this data yesterday and 
what did I actually believe 
was the truth yesterday?
“A temporal database is a database with built-in 
support for handling data involving time…” 
–Wikipedia 
”
A Little History… 
Need for temporal support identified as early as 1992 
Initial attempts to get support for this into the SQL 
standard were rejected 
Finally made it into the SQL:2011 standard
Some Sample Data 
Owner Property 
Jeremy ‘Some place’
What forms of temporal data 
are usually stored?
Temporal Aspects 
Decision Time 
Valid Time 
Transaction Time 
A table that implements one of these is temporal, two 
is bi-temporal, more is multi-temporal
Decision Time 
Records when a decision was taken 
Stored as a timestamp 
You may be doing this already…
Decision Time Example 
Owner Property Decision Time 
Jeremy ‘Some place’ 2012-09-28 
Adam ‘Some place’ 2014-02-21
Valid Time 
The time during which a fact is true with respect to the 
real world 
Modelled as a range between two timestamps 
Closed at lower bound, can be open at upper bound
Valid Time Example 
Owner Property StartVT EndVT 
Jeremy ‘Some place’ 2012-09-28 2014-02-20 
Adam ‘Some place’ 2014-02-21 ∞
Valid Time Example 
Owner Property StartVT EndVT 
Jeremy ‘Some place’ 2012-09-28 2014-03-20 
Adam ‘Some place’ 2014-03-21 ∞
Transaction Time 
The time period during which a fact stored in the 
database is considered to be true 
Modelled as a range between two timestamps 
Closed at lower bound, can be open at upper bound
Transaction Time Example 
Owner Property StartVT EndVT StartTT EndTT 
Jeremy ‘Some 
place’ 
2012-09-2 
8 
2014-02-2 
0 
2012-09-2 
8 
2014-09-0 
9 
Adam ‘Some 
place’ 
2014-02-2 
1 ∞ 2014-02-2 
1 
2014-09-0 
9 
Jeremy ‘Some 
place’ 
2012-09-2 
8 
2014-03-2 
0 
2014-09-0 
9 ∞ 
Adam ‘Some 
place’ 
2014-03-2 
1 ∞ 2014-09-0 
9 ∞
Valid Time and Transaction 
Time are Orthogonal 
Valid Time 
Transaction Time
Enough theory! How do I add 
this stuff to my db schema?
SQL:2011 Temporal 
Additions 
! 
PERIOD type for date ranges in table definitions 
Can query for data in a period using new predicates 
CONTAINS, OVERLAPS, EQUALS, PRECEDES and 
IMMEDIATELY SUCCEEDS 
Can also update or delete data matching a portion of a 
period using FOR PORTION OF {period_name} FROM 
{date} TO {date}
Implementing Valid Time 
Done by adding columns for start and end with a 
period constraint on the columns 
Period must also be included as part of the primary key
Table Definition using Valid 
Time 
CREATE TABLE Emp( 
ENo INTEGER, 
StartVT DATE, 
EndVT DATE, 
EDept INTEGER, 
PERIOD FOR EValidTime (StartVT, EndVT), 
PRIMARY KEY (ENo, EValidTime WITHOUT OVERLAPS), 
)
Foreign Key Problems… 
It’s possible that rows in child tables may reference 
rows in parent tables that are not currently valid and 
vice versa 
Therefore foreign key constraints have to be updated 
where needed to include period data
Valid time foreign key 
definition 
ALTER TABLE Emp 
ADD FOREIGN KEY (Edept, PERIOD EValidTime) 
REFERENCES Dept (DNo, PERIOD DValidTime)
Querying a Table using Valid 
Time 
SELECT Ename, Edept 
FROM Emp 
WHERE ENo = 22217 AND 
EValidTime CONTAINS DATE ‘2011-01-02’; 
! 
SELECT Ename, Edept 
FROM Emp 
WHERE ENo = 22217 AND 
EValidTime OVERLAPS 
PERIOD (DATE ‘2010-01-01', DATE ‘2011-01-01');
Implementing Transaction 
Time 
RDBMS automatically creates a snapshot when data is 
updated or deleted 
Done by adding columns for start, end and a period for 
them 
Must also add WITH SYSTEM VERSIONING to create 
table statement
Table Definition using 
Transaction Time 
CREATE TABLE Emp 
ENo INTEGER, 
Sys_start TIMESTAMP(12) GENERATED 
ALWAYS AS ROW START, 
Sys_end TIMESTAMP(12) GENERATED 
ALWAYS AS ROW END, 
EName VARCHAR(30), 
PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end) 
) WITH SYSTEM VERSIONING
Querying a Table using 
Transaction Time 
SELECT ENo,EName,Sys_Start,Sys_End 
FROM Emp FOR SYSTEM_TIME AS OF 
TIMESTAMP '2011-01-02 00:00:00’; 
! 
SELECT ENo,EName,Sys_Start,Sys_End 
FROM Emp FOR SYSTEM_TIME FROM 
TIMESTAMP '2011-01-02 00:00:00’TO 
TIMESTAMP '2011-12-31 00:00:00’;
Bi-Temporal table definition 
CREATE TABLE Emp( 
ENo INTEGER, 
StartVT DATE, 
EndVT DATE, 
EDept INTEGER, 
PERIOD FOR EValidTime (StartVT, EndVT), 
Sys_start TIMESTAMP(12) GENERATED ALWAYS AS ROW START, 
Sys_end TIMESTAMP(12) GENERATED ALWAYS AS ROW END, 
EName VARCHAR(30), 
PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), 
PRIMARY KEY (ENo, EValidTime WITHOUT OVERLAPS), 
FOREIGN KEY (Edept, PERIOD EValidTime) 
REFERENCES Dept (DNo, PERIOD DValidTime) 
) WITH SYSTEM VERSIONING
Who supports SQL:2011 
Temporal? 
IBM DB2. Called “Time Travel Queries”, although 
different syntax for FOR SYSTEM_TIME AS OF 
Oracle 12c, in compliance with SQL:2011 
Others?
Further Reading 
‘Developing Time Oriented Applications in SQL’ by 
Richard Snodgrass 
‘Temporal Features in SQL:2011’ 
‘Time and Relational Theory: Temporal Databases in 
the Relational Model and SQL'
Thanks for listening 
Any questions? 
Contact me: 
@JCook21 
jeremycook0@gmail.com 
I’d love some feedback!

More Related Content

PDF
Tracking your data across the fourth dimension
Jeremy Cook
 
PDF
Tracking your data across the fourth dimension
Jeremy Cook
 
ODP
Turbo charge your logs
Jeremy Cook
 
ODP
Accelerate your web app with a layer of Varnish
Jeremy Cook
 
PDF
Beyond MVC: from Model to Domain
Jeremy Cook
 
PDF
Beyond MVC: from Model to Domain
Jeremy Cook
 
PDF
Temporal database
Nhất Linh Châu
 
PPTX
Temporal databases
Dabbal Singh Mahara
 
Tracking your data across the fourth dimension
Jeremy Cook
 
Tracking your data across the fourth dimension
Jeremy Cook
 
Turbo charge your logs
Jeremy Cook
 
Accelerate your web app with a layer of Varnish
Jeremy Cook
 
Beyond MVC: from Model to Domain
Jeremy Cook
 
Beyond MVC: from Model to Domain
Jeremy Cook
 
Temporal database
Nhất Linh Châu
 
Temporal databases
Dabbal Singh Mahara
 

Similar to Track your data across the fourth dimension (20)

PDF
Unit 5_ Advanced Database Models, Systems, and Applications.pdf
COSMOS58
 
PDF
Checking and verifying temporal data
IJDMS
 
PDF
MariaDB Temporal Tables
Federico Razzoli
 
PDF
MariaDB Temporal Tables
Federico Razzoli
 
PPT
tempDB.ppt
GopiBala5
 
PDF
Management of Bi-Temporal Properties of Sql/Nosql Based Architectures – A Re...
lyn kurian
 
PDF
Time Travelling With DB2 10 For zOS
Laura Hood
 
PPTX
Back to the future - Temporal Table in SQL Server 2016
Stéphane Fréchette
 
PDF
Temporal Databases: Queries
torp42
 
PDF
SQLSat462 Parma 2015
pceglie
 
PDF
BI-TEMPORAL IMPLEMENTATION IN RELATIONAL DATABASE MANAGEMENT SYSTEMS: MS SQ...
lyn kurian
 
PDF
Webinar - MariaDB Temporal Tables: a demonstration
Federico Razzoli
 
PPT
Temporal
sunsie
 
PDF
Temporal Case Management 1998
David Tryon
 
PDF
M|18 Querying Data at a Previous Point in Time
MariaDB plc
 
PDF
Temporal Data
Command Prompt., Inc
 
PDF
Oracle 12c Application development
pasalapudi123
 
ODP
Bi-temporal rdbms 2014
Tomm Carr
 
PPTX
SQL Server Temporal Tables
Greg McMurray
 
PPT
Teradata 13.10
Teradata
 
Unit 5_ Advanced Database Models, Systems, and Applications.pdf
COSMOS58
 
Checking and verifying temporal data
IJDMS
 
MariaDB Temporal Tables
Federico Razzoli
 
MariaDB Temporal Tables
Federico Razzoli
 
tempDB.ppt
GopiBala5
 
Management of Bi-Temporal Properties of Sql/Nosql Based Architectures – A Re...
lyn kurian
 
Time Travelling With DB2 10 For zOS
Laura Hood
 
Back to the future - Temporal Table in SQL Server 2016
Stéphane Fréchette
 
Temporal Databases: Queries
torp42
 
SQLSat462 Parma 2015
pceglie
 
BI-TEMPORAL IMPLEMENTATION IN RELATIONAL DATABASE MANAGEMENT SYSTEMS: MS SQ...
lyn kurian
 
Webinar - MariaDB Temporal Tables: a demonstration
Federico Razzoli
 
Temporal
sunsie
 
Temporal Case Management 1998
David Tryon
 
M|18 Querying Data at a Previous Point in Time
MariaDB plc
 
Temporal Data
Command Prompt., Inc
 
Oracle 12c Application development
pasalapudi123
 
Bi-temporal rdbms 2014
Tomm Carr
 
SQL Server Temporal Tables
Greg McMurray
 
Teradata 13.10
Teradata
 
Ad

Recently uploaded (20)

PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Ad

Track your data across the fourth dimension

  • 1. Text Tracking your Data Across the Fourth Dimension Wellington Waterloo Web Makers Meetup
  • 2. “In physics, spacetime is any mathematical model that combines space and time into a single interwoven continuum.” –Wikipedia
  • 3. Databases are Good at ‘Now’ CRUD Create data Read data Update data Delete data
  • 4. Bread and Butter Queries How many people work in department X? What’s the total amount paid in commissions by department? What was the top selling product in the last year?
  • 5. The Fourth Dimension… Compare reporting relationships one month ago, today and in one months time Show me all changes made to this data over time As of one month ago, what did I believe to be the truth about this data yesterday and what did I actually believe was the truth yesterday?
  • 6. “A temporal database is a database with built-in support for handling data involving time…” –Wikipedia ”
  • 7. A Little History… Need for temporal support identified as early as 1992 Initial attempts to get support for this into the SQL standard were rejected Finally made it into the SQL:2011 standard
  • 8. Some Sample Data Owner Property Jeremy ‘Some place’
  • 9. What forms of temporal data are usually stored?
  • 10. Temporal Aspects Decision Time Valid Time Transaction Time A table that implements one of these is temporal, two is bi-temporal, more is multi-temporal
  • 11. Decision Time Records when a decision was taken Stored as a timestamp You may be doing this already…
  • 12. Decision Time Example Owner Property Decision Time Jeremy ‘Some place’ 2012-09-28 Adam ‘Some place’ 2014-02-21
  • 13. Valid Time The time during which a fact is true with respect to the real world Modelled as a range between two timestamps Closed at lower bound, can be open at upper bound
  • 14. Valid Time Example Owner Property StartVT EndVT Jeremy ‘Some place’ 2012-09-28 2014-02-20 Adam ‘Some place’ 2014-02-21 ∞
  • 15. Valid Time Example Owner Property StartVT EndVT Jeremy ‘Some place’ 2012-09-28 2014-03-20 Adam ‘Some place’ 2014-03-21 ∞
  • 16. Transaction Time The time period during which a fact stored in the database is considered to be true Modelled as a range between two timestamps Closed at lower bound, can be open at upper bound
  • 17. Transaction Time Example Owner Property StartVT EndVT StartTT EndTT Jeremy ‘Some place’ 2012-09-2 8 2014-02-2 0 2012-09-2 8 2014-09-0 9 Adam ‘Some place’ 2014-02-2 1 ∞ 2014-02-2 1 2014-09-0 9 Jeremy ‘Some place’ 2012-09-2 8 2014-03-2 0 2014-09-0 9 ∞ Adam ‘Some place’ 2014-03-2 1 ∞ 2014-09-0 9 ∞
  • 18. Valid Time and Transaction Time are Orthogonal Valid Time Transaction Time
  • 19. Enough theory! How do I add this stuff to my db schema?
  • 20. SQL:2011 Temporal Additions ! PERIOD type for date ranges in table definitions Can query for data in a period using new predicates CONTAINS, OVERLAPS, EQUALS, PRECEDES and IMMEDIATELY SUCCEEDS Can also update or delete data matching a portion of a period using FOR PORTION OF {period_name} FROM {date} TO {date}
  • 21. Implementing Valid Time Done by adding columns for start and end with a period constraint on the columns Period must also be included as part of the primary key
  • 22. Table Definition using Valid Time CREATE TABLE Emp( ENo INTEGER, StartVT DATE, EndVT DATE, EDept INTEGER, PERIOD FOR EValidTime (StartVT, EndVT), PRIMARY KEY (ENo, EValidTime WITHOUT OVERLAPS), )
  • 23. Foreign Key Problems… It’s possible that rows in child tables may reference rows in parent tables that are not currently valid and vice versa Therefore foreign key constraints have to be updated where needed to include period data
  • 24. Valid time foreign key definition ALTER TABLE Emp ADD FOREIGN KEY (Edept, PERIOD EValidTime) REFERENCES Dept (DNo, PERIOD DValidTime)
  • 25. Querying a Table using Valid Time SELECT Ename, Edept FROM Emp WHERE ENo = 22217 AND EValidTime CONTAINS DATE ‘2011-01-02’; ! SELECT Ename, Edept FROM Emp WHERE ENo = 22217 AND EValidTime OVERLAPS PERIOD (DATE ‘2010-01-01', DATE ‘2011-01-01');
  • 26. Implementing Transaction Time RDBMS automatically creates a snapshot when data is updated or deleted Done by adding columns for start, end and a period for them Must also add WITH SYSTEM VERSIONING to create table statement
  • 27. Table Definition using Transaction Time CREATE TABLE Emp ENo INTEGER, Sys_start TIMESTAMP(12) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(12) GENERATED ALWAYS AS ROW END, EName VARCHAR(30), PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end) ) WITH SYSTEM VERSIONING
  • 28. Querying a Table using Transaction Time SELECT ENo,EName,Sys_Start,Sys_End FROM Emp FOR SYSTEM_TIME AS OF TIMESTAMP '2011-01-02 00:00:00’; ! SELECT ENo,EName,Sys_Start,Sys_End FROM Emp FOR SYSTEM_TIME FROM TIMESTAMP '2011-01-02 00:00:00’TO TIMESTAMP '2011-12-31 00:00:00’;
  • 29. Bi-Temporal table definition CREATE TABLE Emp( ENo INTEGER, StartVT DATE, EndVT DATE, EDept INTEGER, PERIOD FOR EValidTime (StartVT, EndVT), Sys_start TIMESTAMP(12) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(12) GENERATED ALWAYS AS ROW END, EName VARCHAR(30), PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY (ENo, EValidTime WITHOUT OVERLAPS), FOREIGN KEY (Edept, PERIOD EValidTime) REFERENCES Dept (DNo, PERIOD DValidTime) ) WITH SYSTEM VERSIONING
  • 30. Who supports SQL:2011 Temporal? IBM DB2. Called “Time Travel Queries”, although different syntax for FOR SYSTEM_TIME AS OF Oracle 12c, in compliance with SQL:2011 Others?
  • 31. Further Reading ‘Developing Time Oriented Applications in SQL’ by Richard Snodgrass ‘Temporal Features in SQL:2011’ ‘Time and Relational Theory: Temporal Databases in the Relational Model and SQL'
  • 32. Thanks for listening Any questions? Contact me: @JCook21 [email protected] I’d love some feedback!