Skip to content
Snippets Groups Projects
Commit e8616362 authored by Bruce Momjian's avatar Bruce Momjian
Browse files

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: default avatar <vodevsh@gmail.com>

Discussion: https://postgr.es/m/152698651482.26744.15456677499485530703@wrigleys.postgresql.org

Backpatch-through: 9.3
parent af050c07
No related branches found
No related tags found
No related merge requests found
...@@ -2661,19 +2661,6 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> < ...@@ -2661,19 +2661,6 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> <
to each field if any field is negative. to each field if any field is negative.
</para> </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> <para>
In the verbose input format, and in some fields of the more compact In the verbose input format, and in some fields of the more compact
input formats, field values can have fractional parts; for example input formats, field values can have fractional parts; for example
...@@ -2725,6 +2712,33 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> < ...@@ -2725,6 +2712,33 @@ P <optional> <replaceable>years</>-<replaceable>months</>-<replaceable>days</> <
</tgroup> </tgroup>
</table> </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>
<sect2 id="datatype-interval-output"> <sect2 id="datatype-interval-output">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment