Developing Time-Oriented Applications in SQL Richard T. Snodgrass

DATA TYPES

UniSQL Implementation Examples

 

   

Detailed Contents

This document outlines temporal data type support for the UniSQL DBMS. It follows the general outline of the TDB book and is arranged in the following manner.

Instants and Intervals

Operations
Examples

Periods

Operations
Examples


  

Instants and Intervals (UniSQL)

Similar to SQL-92, UniSQL supports the DATE, TIME, and TIMESTAMP data types, however expresses them differently. For example, it uses DATE '01/01/1997' to express DATE '1997-01-01'. TIMESTAMPs are constrained to a granularity of a second. Their range is only January 1, 1970 through 03:14:07 January 19, 2038. TIMEs are also to a granularity of a second. In addition, substracting two DATEs yields an integral number of days; substracting two TIME or TIMESTAMP values will yield an integral number of second. Some other operations in SQL-92 such as TIME WITH TIME ZONE are not supported in UniSQL.

Operations

SQL-92 
 
UniSQL Equivalent 
 
Types:
DATE DATE, must fall between 0 and 9999 AD, constrained by Gregorian calendar
TIME TIME (to second granularity)
TIMESTAMP TIMESTAMP (to second granularity), range from 00:00:00 January 1, 1970 through 03:14:07 January 19, 2038 GMT
TIME WITH TIME ZONE No equivalent
TIMESTAMP WITH TIME ZONE No equivalent
INTERVAL YEAR TO MONTH No equivalent
INTERVAL DAY TO SECOND No equivalent (substracting two DATEs yields an integral number of days; substracting two TIME or TIMESATMP values will yield an integral number of seconds)
Literals:
DATE '1997-01-01' DATE '01/01/1997', 'mm/dd[/yyyy]'
TIME '12:34:56' TIME '12:34:56', 'hh:mm[:ss][am/pm]'
TIMESTAMP '1997-01-01 12:34:56' TIMESTAMP '01/01/1997 12:34:56', 'mm/dd[/yyyy] hh:mm[:ss][am/pm]'
INTERVAL '3-4' YEAR TO MONTH Not possible
INTERVAL '1 23:45:12' DAY TO SECOND 'TIME-TIME=171812 (seconds)'
Predicates:
d1 = d2 d1 = d2
d1 < d2 d1 < d2
d1 <> d2 d1 <> d2
d1 BETWEEN d2 AND d3 d1 BETWEEN d2 AND d3
i1 = i2 j1 = j2
i1 < i2 j1 < j2
i1 <> i2 j1 <> j2
i1 BETWEEN i2 AND i3 j1 BETWEEN j2 AND j3
d IS NULL d IS NULL
i IS NULL j IS NULL
(d1, i2) OVERLAPS (d3, d4) d1 <= d4 AND d3 <= (d1 + j2)
Datetime Constructors:
d + i d + j
i + d j + d
d - i d - j
d AT i Not supported
d AT LOCAL Not supported
CURRENT_DATE Not supported
CURRENT_TIME Not supported
CURRENT_TIMESTAMP Not supported
Internal Constructors:
i1 + i2 j1 + j2
i1 - i2 j1 - j2
d1 - d2 qual d1 - d2 (substracting two DATEs yields an integral number of days)
d1 - d2 INTERVAL MONTH Not possible
i * n j * n
n * i n * j
i / i j / j
+ i + j
- i - j
Other Operators:
CAST(d AS DATE) CAST(d AS DATE)
CAST(d AS TIME) CAST(d AS TIME) (where d is a TIME)
CAST(d AS TIMESTAMP) (where d is a DATE) CAST(d AS TIMESTAMP) (where d is a DATE)
CAST(d AS TIMESTAMP) (where d is a TIME) CAST(d AS TIMESTAMP) (where d is a TIME)
CAST(i AS INTERVAL YEAR TO MONTH) Not possible
CAST(i AS INTERVAL DAY TO SECOND) j
CAST(d AS CHAR) CAST(d AS CHAR)
CAST(i AS CHAR) CAST(i AS CHAR)
CAST(i AS INTEGER) (where i is a DAY) j (already an integer)
CAST(i AS INTEGER) (where i is a SECOND) i already an integer
EXTRACT(DAY from d) EXTRACT(DAY from d)
EXTRACT(DAY from i) Not possible
EXTRACT(HOUR from i) Not possible
Operators not in SQL-92:
Convert d to Julian day Not supported
Convert Julian day n to DATE Not supported
Pick the earliest date Not supported
Pick the latest date Not supported
Pick the last day of the month Not supported
Get the next day of the week Not supported

Examples

Schema for the Examples

Employee Table (Test Data)  

Name 
STRING
Birthdate 
DATE
Project_time 
TIME
Checkin_time 
TIMESTAMP
Checkout_time 
TIMESTAMP

UniSQL Sample Queries
Sample Output


  

Periods (UniSQL)

Operations

SQL-92 
 
UniSQL Equivalent 
 
Types:
period No corresponding type, can be considered as two dates [DATE, DATE)
Predicates:
p equals q p1 = q1 AND p2 = q2
p before q p2 < q1
p before-1 q q2 < p1
p meets q p2 = q1
p meets-1 q q2 = p1
p overlaps q p1 < q1 AND q1 < p2
p overlaps-1 q q1 < p1 AND p1 < q2
p during q q1 < p1 AND p2 < q2
p during-1 q p1 < q1 AND q2 < p2
p starts q p1 = q1 AND p2 < q2
p starts-1 q p1 = q1 AND q2 < p2
p finishes q q1 < p1 AND p2 = q2
p finishes-1 q p1 < q1 AND p2 = q2
p OVERLAPS q p1 < q2 AND q1 < p2
p IS NULL p1 IS NULL
Datetime Constructors:
beginning(p) p1
previous(p) p1-1
last(p) p2-1(for closed-open representation p=[p1, p2)); p2 (for closed-closed representation)
ending(p) p2
Interval Constructors:
duration(p) p2-p1
extract_time_zone(p) Not supported
Period Constructors:
p + i [p1 + j, p2 + j)
i + p [p1 + j, p2 + j)
p - i [p1 - j, p2 - j)
a extend b Not possible
p extend q Not possible
p extend a Not possible
a extend p Not possible
p INTERSECT q Not possible
p - q Not possible
p UNION q Not possible
p AT TIME ZONE i Not supported
p AT LOCAL Not supported
Other Operators:
CAST(a AS PERIOD) [a, a+1)
CAST(p AS CHAR) Not possible

Examples

Schema for the Examples

Employee Table (Test Data)

Name 
STRING
Birthdate 
DATE
Project_time 
TIME
Checkin_time 
TIMESTAMP
Checkout_time 
TIMESTAMP

UniSQL Sample Queries
Sample Output

HTML Credits

Qing Yan, University of Arizona (qyan@lectura.cs.arizona.edu)
Rachana R. Shah, University of Arizona (rachana@lectura.cs.arizona.edu)
Jian Yang,Department of Computer Science, University of Arizona (yangjian@cs.arizona.edu)
November 10, 1998 (Last Update)

UniSQL-Specific Code Credits

Qing Yan, University of Arizona (qyan@lectura.cs.arizona.edu)
November 30, 1997 (Last Update)