Skip to content

Commit e861636

Browse files
committed
doc: show how interval's 3 unit buckets behave using EXTRACT()
This clarifies when justify_days() and justify_hours() are useful. Paragraph moved too. Reported-by: vodevsh@gmail.com Discussion: https://postgr.es/m/152698651482.26744.15456677499485530703@wrigleys.postgresql.org Backpatch-through: 9.3
1 parent af050c0 commit e861636

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

doc/src/sgml/datatype.sgml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,19 +2661,6 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> <
26612661
to each field if any field is negative.
26622662
</para>
26632663

2664-
<para>
2665-
Internally <type>interval</> values are stored as months, days,
2666-
and seconds. This is done because the number of days in a month
2667-
varies, and a day can have 23 or 25 hours if a daylight savings
2668-
time adjustment is involved. The months and days fields are integers
2669-
while the seconds field can store fractions. Because intervals are
2670-
usually created from constant strings or <type>timestamp</> subtraction,
2671-
this storage method works well in most cases. Functions
2672-
<function>justify_days</> and <function>justify_hours</> are
2673-
available for adjusting days and hours that overflow their normal
2674-
ranges.
2675-
</para>
2676-
26772664
<para>
26782665
In the verbose input format, and in some fields of the more compact
26792666
input formats, field values can have fractional parts; for example
@@ -2725,6 +2712,33 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> <
27252712
</tgroup>
27262713
</table>
27272714

2715+
<para>
2716+
Internally <type>interval</type> values are stored as months, days,
2717+
and seconds. This is done because the number of days in a month
2718+
varies, and a day can have 23 or 25 hours if a daylight savings
2719+
time adjustment is involved. The months and days fields are integers
2720+
while the seconds field can store fractions. Because intervals are
2721+
usually created from constant strings or <type>timestamp</type> subtraction,
2722+
this storage method works well in most cases, but can cause unexpected
2723+
results:
2724+
2725+
<programlisting>
2726+
SELECT EXTRACT(hours from '80 minutes'::interval);
2727+
date_part
2728+
-----------
2729+
1
2730+
2731+
SELECT EXTRACT(days from '80 hours'::interval);
2732+
date_part
2733+
-----------
2734+
0
2735+
</programlisting>
2736+
2737+
Functions <function>justify_days</function> and
2738+
<function>justify_hours</function> are available for adjusting days
2739+
and hours that overflow their normal ranges.
2740+
</para>
2741+
27282742
</sect2>
27292743

27302744
<sect2 id="datatype-interval-output">

0 commit comments

Comments
 (0)