- We know can we can subtract two times to get the difference between two point in times. The result is an interval.
Example:
SELECT (TIME '12:12:13' - TIME '11:11:11')
MINUTE
Result is 61 .
The output is INTERVAL MINUTE
- We can add/subtract an interval to a Time to get another point of time as the result
SELECT TIME '12:11:11' + INTERVAL '11' MINUTE
Result is 12:22:11
The data type of the result is TIME.
Ever
wondered what would be the result of following query : SELECT TIME '12:12:13' +
TIME '11:11:11'
Well
, I wondered and experts called it as illogical :)
There is nothing called addition of two
TIME's. It does not symbolize anything.
We
add Interval to a Starting time to get the end time.
Adding
two dates is also illogical , however adding two dates does not fail.
We
get a result which is an integer.
We
know that date are saved internally as integers, the result is actually the sum
of two integers.
select
date '2012-12-12' + date '2011-12-12';
Result
: 1469944
Another way to look at it: a TIME is a point (0 dimensions); an interval is
a line (1 dimension).
You can:
- find the distance between two points (time - time);
- construct a line beginning at a point (time + or - interval);
- place one line at the end of another (interval + interval);
- find the difference in length of two lines (interval - interval).
You cannot add two points (time + time).
a line (1 dimension).
You can:
- find the distance between two points (time - time);
- construct a line beginning at a point (time + or - interval);
- place one line at the end of another (interval + interval);
- find the difference in length of two lines (interval - interval).
You cannot add two points (time + time).
No comments:
Post a Comment