Skip to content

Commit 8f203c6

Browse files
committed
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
1 parent 3d2b6cd commit 8f203c6

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

doc/src/sgml/datatype.sgml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,15 +2699,18 @@ P <optional> <replaceable>years</replaceable>-<replaceable>months</replaceable>-
26992699
</para>
27002700

27012701
<para>
2702-
In the verbose input format, and in some fields of the more compact
2703-
input formats, field values can have fractional parts; for example
2704-
<literal>'1.5 week'</literal> or <literal>'01:02:03.45'</literal>. Such input is
2705-
converted to the appropriate number of months, days, and seconds
2706-
for storage. When this would result in a fractional number of
2707-
months or days, the fraction is added to the lower-order fields
2708-
using the conversion factors 1 month = 30 days and 1 day = 24 hours.
2709-
For example, <literal>'1.5 month'</literal> becomes 1 month and 15 days.
2710-
Only seconds will ever be shown as fractional on output.
2702+
Field values can have fractional parts: for example, <literal>'1.5
2703+
weeks'</literal> or <literal>'01:02:03.45'</literal>. However,
2704+
because interval internally stores only three integer units (months,
2705+
days, microseconds), fractional units must be spilled to smaller
2706+
units. Fractional parts of units greater than months is truncated to
2707+
be an integer number of months, e.g. <literal>'1.5 years'</literal>
2708+
becomes <literal>'1 year 6 mons'</literal>. Fractional parts of
2709+
weeks and days are computed to be an integer number of days and
2710+
microseconds, assuming 30 days per month and 24 hours per day, e.g.,
2711+
<literal>'1.75 months'</literal> becomes <literal>1 mon 22 days
2712+
12:00:00</literal>. Only seconds will ever be shown as fractional
2713+
on output.
27112714
</para>
27122715

27132716
<para>
@@ -2751,10 +2754,10 @@ P <optional> <replaceable>years</replaceable>-<replaceable>months</replaceable>-
27512754

27522755
<para>
27532756
Internally <type>interval</type> values are stored as months, days,
2754-
and seconds. This is done because the number of days in a month
2757+
and microseconds. This is done because the number of days in a month
27552758
varies, and a day can have 23 or 25 hours if a daylight savings
27562759
time adjustment is involved. The months and days fields are integers
2757-
while the seconds field can store fractions. Because intervals are
2760+
while the microseconds field can store fractional seconds. Because intervals are
27582761
usually created from constant strings or <type>timestamp</type> subtraction,
27592762
this storage method works well in most cases, but can cause unexpected
27602763
results:

0 commit comments

Comments
 (0)