aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2018-06-23 23:32:41 -0400
committerBruce Momjian <bruce@momjian.us>2018-06-23 23:32:41 -0400
commitc1975c1af7c2120277c57b1f40996b5d94cf22f6 (patch)
treedc9514eb616a74e604d5795e143791fca06dfa54
parentb742010890ab30dc0ef9e23fc341fc60d99b951a (diff)
downloadpostgresql-c1975c1af7c2120277c57b1f40996b5d94cf22f6.tar.gz
postgresql-c1975c1af7c2120277c57b1f40996b5d94cf22f6.zip
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
-rw-r--r--doc/src/sgml/datatype.sgml40
1 files changed, 27 insertions, 13 deletions
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index 2284a48729b..2cfba1d36d2 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -2671,19 +2671,6 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> <
</para>
<para>
- Internally <type>interval</> values are stored as months, days,
- and seconds. 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
- usually created from constant strings or <type>timestamp</> subtraction,
- this storage method works well in most cases. Functions
- <function>justify_days</> and <function>justify_hours</> are
- available for adjusting days and hours that overflow their normal
- ranges.
- </para>
-
- <para>
In the verbose input format, and in some fields of the more compact
input formats, field values can have fractional parts; for example
<literal>'1.5 week'</> or <literal>'01:02:03.45'</>. Such input is
@@ -2734,6 +2721,33 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> <
</tgroup>
</table>
+ <para>
+ Internally <type>interval</type> values are stored as months, days,
+ and seconds. 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
+ usually created from constant strings or <type>timestamp</type> subtraction,
+ this storage method works well in most cases, but can cause unexpected
+ results:
+
+<programlisting>
+SELECT EXTRACT(hours from '80 minutes'::interval);
+ date_part
+-----------
+ 1
+
+SELECT EXTRACT(days from '80 hours'::interval);
+ date_part
+-----------
+ 0
+</programlisting>
+
+ Functions <function>justify_days</function> and
+ <function>justify_hours</function> are available for adjusting days
+ and hours that overflow their normal ranges.
+ </para>
+
</sect2>
<sect2 id="datatype-interval-output">