From: Bruce Momjian Date: Tue, 3 Aug 2021 16:17:57 +0000 (-0400) Subject: doc: interval spill method for units greater than months X-Git-Tag: REL9_6_23~11 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=9a01a2de85e550ab40193dc45482c736dc9c4dbf;p=postgresql.git doc: interval spill method for units greater than months Units are _truncated_ to months, but only in back branches since the recent commit. Reported-by: Bryn Llewellyn Discussion: https://postgr.es/m/BDAE4B56-3337-45A2-AC8A-30593849D6C0@yugabyte.com Backpatch-through: 9.6 to 14 --- diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 0868856b1f8..c3379a18ad1 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -2717,15 +2717,18 @@ P years-months-days < - In the verbose input format, and in some fields of the more compact - input formats, field values can have fractional parts; for example - '1.5 week' or '01:02:03.45'. Such input is - converted to the appropriate number of months, days, and seconds - for storage. When this would result in a fractional number of - months or days, the fraction is added to the lower-order fields - using the conversion factors 1 month = 30 days and 1 day = 24 hours. - For example, '1.5 month' becomes 1 month and 15 days. - Only seconds will ever be shown as fractional on output. + Field values can have fractional parts: for example, '1.5 + weeks' or '01:02:03.45'. However, + because interval internally stores only three integer units (months, + days, microseconds), fractional units must be spilled to smaller + units. Fractional parts of units greater than months is truncated to + be an integer number of months, e.g. '1.5 years' + becomes '1 year 6 mons'. Fractional parts of + weeks and days are computed to be an integer number of days and + microseconds, assuming 30 days per month and 24 hours per day, e.g., + '1.75 months' becomes 1 mon 22 days + 12:00:00. Only seconds will ever be shown as fractional + on output. @@ -2769,10 +2772,10 @@ P years-months-days < Internally interval values are stored as months, days, - and seconds. This is done because the number of days in a month + and microseconds. This is done because the number of days in a month varies, and a day can have 23 or 25 hours if a daylight savings time adjustment is involved. The months and days fields are integers - while the seconds field can store fractions. Because intervals are + while the microseconds field can store fractional seconds. Because intervals are usually created from constant strings or timestamp subtraction, this storage method works well in most cases, but can cause unexpected results: