1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Add some documentation about handling of fractions in interval input.

(It's always worked like this, but we never documented it before.)
This commit is contained in:
Tom Lane
2008-11-09 17:09:48 +00:00
parent df7641e25a
commit dbf57d31f8

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.232 2008/11/09 00:28:34 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.233 2008/11/09 17:09:48 tgl Exp $ -->
<chapter id="datatype"> <chapter id="datatype">
<title id="datatype-title">Data Types</title> <title id="datatype-title">Data Types</title>
@ -2413,13 +2413,26 @@ January 8 04:05:06 1999 PST
Internally <type>interval</> values are stored as months, days, Internally <type>interval</> values are stored as months, days,
and seconds. This is done because the number of days in a month 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 varies, and a day can have 23 or 25 hours if a daylight savings
time adjustment is involved. Because intervals are usually created time adjustment is involved. The months and days fields are integers
from constant strings or <type>timestamp</> subtraction, this while the seconds field can store fractions. Because intervals are
storage method works well in most cases. Functions 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 <function>justify_days</> and <function>justify_hours</> are
available for adjusting days and hours that overflow their normal available for adjusting days and hours that overflow their normal
ranges. ranges.
</para> </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
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, <literal>'1.5 month'</> becomes 1 month and 15 days.
Only seconds will ever be shown as fractional on output.
</para>
</sect2> </sect2>
<sect2 id="datatype-interval-output"> <sect2 id="datatype-interval-output">