From 7489eb4d3b7fef2c2eaeb66e3bcb3fb74385b44d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 3 Sep 2013 16:28:56 -0400 Subject: [PATCH] Docs: wording improvements in discussion of timestamp arithmetic. I started out just to fix the broken markup in commit 1c2085766187031eaeaae7db4785b9e1d4241988, but got distracted by copy-editing. I see Bruce already fixed the markup, but I'll commit the wordsmithing anyway. --- doc/src/sgml/func.sgml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 00f8ffb38cb..ee1c957c737 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -6769,9 +6769,9 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS When adding an interval value to (or subtracting an interval value from) a timestamp with time zone - value, the days component advances (or decrements) the date of the + value, the days component advances or decrements the date of the timestamp with time zone by the indicated number of days. - Across daylight saving time changes (with the session time zone set to a + Across daylight saving time changes (when the session time zone is set to a time zone that recognizes DST), this means interval '1 day' does not necessarily equal interval '24 hours'. For example, with the session time zone set to CST7CDT, @@ -6785,8 +6785,8 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS - Note there can be ambiguity in the months returned by - age because different months have a different number of + Note there can be ambiguity in the months field returned by + age because different months have different numbers of days. PostgreSQL's approach uses the month from the earlier of the two dates when calculating partial months. For example, age('2004-06-01', '2004-04-30') uses April to yield @@ -6795,19 +6795,22 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS - Subtraction of dates and timestamps can also be complex. The most - accurate way to perform subtraction is to convert each value to a number - of seconds using EXTRACT(EPOCH FROM ...) and compute the + Subtraction of dates and timestamps can also be complex. One conceptually + simple way to perform subtraction is to convert each value to a number + of seconds using EXTRACT(EPOCH FROM ...), then subtract the + results; this produces the number of seconds between the two values. This will adjust for the number of days in each month, timezone changes, and daylight - saving time adjustments. Operator subtraction of date or timestamp - values returns the number of days (24-hours) and hours/minutes/seconds + saving time adjustments. Subtraction of date or timestamp + values with the - operator + returns the number of days (24-hours) and hours/minutes/seconds between the values, making the same adjustments. The age function returns years, months, days, and hours/minutes/seconds, performing field-by-field subtraction and then adjusting for negative - field values. The following queries, produced with timezone - = 'US/Eastern' and including a daylight saving time change, - illustrates these issues: + field values. The following queries illustrate the differences in these + approaches. The sample results were produced with timezone + = 'US/Eastern'; there is a daylight saving time change between the + two dates used: @@ -6815,7 +6818,7 @@ SELECT EXTRACT(EPOCH FROM timestamptz '2013-07-01 12:00:00') - EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00'); Result: 10537200 SELECT (EXTRACT(EPOCH FROM timestamptz '2013-07-01 12:00:00') - - EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00')) + EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00')) / 60 / 60 / 24; Result: 121.958333333333 SELECT timestamptz '2013-07-01 12:00:00' - timestamptz '2013-03-01 12:00:00'; -- 2.39.5