@@ -8606,7 +8606,8 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
86068606 </para>
86078607 <para>
86088608 Subtract timestamps (converting 24-hour intervals into days,
8609- similarly to <function>justify_hours()</function>)
8609+ similarly to <link
8610+ linkend="function-justify-hours"><function>justify_hours()</function></link>)
86108611 </para>
86118612 <para>
86128613 <literal>timestamp '2001-09-29 03:00' - timestamp '2001-07-27 12:00'</literal>
@@ -8975,35 +8976,35 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
89758976
89768977 <row>
89778978 <entry role="func_table_entry"><para role="func_signature">
8978- <indexterm>
8979+ <indexterm id="function-justify-days" >
89798980 <primary>justify_days</primary>
89808981 </indexterm>
89818982 <function>justify_days</function> ( <type>interval</type> )
89828983 <returnvalue>interval</returnvalue>
89838984 </para>
89848985 <para>
8985- Adjust interval so 30-day time periodsare represented as months
8986+ Adjust interval, converting 30-day time periodsto months
89868987 </para>
89878988 <para>
8988- <literal>justify_days(interval '35 days')</literal>
8989- <returnvalue>1mon 5 days</returnvalue>
8989+ <literal>justify_days(interval '1 year 65 days')</literal>
8990+ <returnvalue>1year 2 mons 5 days</returnvalue>
89908991 </para></entry>
89918992 </row>
89928993
89938994 <row>
89948995 <entry role="func_table_entry"><para role="func_signature">
8995- <indexterm>
8996+ <indexterm id="function-justify-hours" >
89968997 <primary>justify_hours</primary>
89978998 </indexterm>
89988999 <function>justify_hours</function> ( <type>interval</type> )
89999000 <returnvalue>interval</returnvalue>
90009001 </para>
90019002 <para>
9002- Adjust interval so 24-hour time periodsare represented as days
9003+ Adjust interval, converting 24-hour time periodsto days
90039004 </para>
90049005 <para>
9005- <literal>justify_hours(interval '27 hours')</literal>
9006- <returnvalue>1 day 03:00 :00</returnvalue>
9006+ <literal>justify_hours(interval '50 hours 10 minutes ')</literal>
9007+ <returnvalue>2 days 02:10 :00</returnvalue>
90079008 </para></entry>
90089009 </row>
90099010
@@ -9426,13 +9427,19 @@ EXTRACT(<replaceable>field</replaceable> FROM <replaceable>source</replaceable>)
94269427 The <function>extract</function> function retrieves subfields
94279428 such as year or hour from date/time values.
94289429 <replaceable>source</replaceable> must be a value expression of
9429- type <type>timestamp</type>, <type>time </type>,or <type>interval </type>.
9430- (Expressions of type <type>date </type> are
9431- cast to <type>timestamp</type> and can therefore be used as
9432- well.) <replaceable>field</replaceable> is an identifier or
9430+ type <type>timestamp</type>, <type>date </type>, <type>time </type>,
9431+ or <type>interval </type>. (Timestamps and times can be with or
9432+ without time zone.)
9433+ <replaceable>field</replaceable> is an identifier or
94339434 string that selects what field to extract from the source value.
9435+ Not all fields are valid for every input data type; for example, fields
9436+ smaller than a day cannot be extracted from a <type>date</type>, while
9437+ fields of a day or more cannot be extracted from a <type>time</type>.
94349438 The <function>extract</function> function returns values of type
94359439 <type>numeric</type>.
9440+ </para>
9441+
9442+ <para>
94369443 The following are valid field names:
94379444
94389445 <!-- alphabetical -->
@@ -9441,40 +9448,36 @@ EXTRACT(<replaceable>field</replaceable> FROM <replaceable>source</replaceable>)
94419448 <term><literal>century</literal></term>
94429449 <listitem>
94439450 <para>
9444- The century
9451+ The century; for <type>interval</type> values, the year field
9452+ divided by 100
94459453 </para>
94469454
94479455<screen>
94489456SELECT EXTRACT(CENTURY FROM TIMESTAMP '2000-12-16 12:21:13');
94499457<lineannotation>Result: </lineannotation><computeroutput>20</computeroutput>
94509458SELECT EXTRACT(CENTURY FROM TIMESTAMP '2001-02-16 20:38:40');
94519459<lineannotation>Result: </lineannotation><computeroutput>21</computeroutput>
9460+ SELECT EXTRACT(CENTURY FROM DATE '0001-01-01 AD');
9461+ <lineannotation>Result: </lineannotation><computeroutput>1</computeroutput>
9462+ SELECT EXTRACT(CENTURY FROM DATE '0001-12-31 BC');
9463+ <lineannotation>Result: </lineannotation><computeroutput>-1</computeroutput>
9464+ SELECT EXTRACT(CENTURY FROM INTERVAL '2001 years');
9465+ <lineannotation>Result: </lineannotation><computeroutput>20</computeroutput>
94529466</screen>
9453-
9454- <para>
9455- The first century starts at 0001-01-01 00:00:00 AD, although
9456- they did not know it at the time. This definition applies to all
9457- Gregorian calendar countries. There is no century number 0,
9458- you go from -1 century to 1 century.
9459-
9460- If you disagree with this, please write your complaint to:
9461- Pope, Cathedral Saint-Peter of Roma, Vatican.
9462- </para>
94639467 </listitem>
94649468 </varlistentry>
94659469
94669470 <varlistentry>
94679471 <term><literal>day</literal></term>
94689472 <listitem>
94699473 <para>
9470- For <type>timestamp</type> values, the day( of the month) field
9471- (1–31) ; for <type>interval</type> values, the number of days
9474+ The day of the month (1–31); for <type>interval</type>
9475+ values, the number of days
94729476 </para>
94739477
94749478<screen>
94759479SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40');
94769480<lineannotation>Result: </lineannotation><computeroutput>16</computeroutput>
9477-
94789481SELECT EXTRACT(DAY FROM INTERVAL '40 days 1 minute');
94799482<lineannotation>Result: </lineannotation><computeroutput>40</computeroutput>
94809483</screen>
@@ -9548,10 +9551,8 @@ SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
95489551<screen>
95499552SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
95509553<lineannotation>Result: </lineannotation><computeroutput>982384720.120000</computeroutput>
9551-
95529554SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40.12');
95539555<lineannotation>Result: </lineannotation><computeroutput>982355920.120000</computeroutput>
9554-
95559556SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
95569557<lineannotation>Result: </lineannotation><computeroutput>442800.000000</computeroutput>
95579558</screen>
@@ -9579,7 +9580,8 @@ SELECT to_timestamp(982384720.12);
95799580 <term><literal>hour</literal></term>
95809581 <listitem>
95819582 <para>
9582- The hour field (0–23)
9583+ The hour field (0–23 in timestamps, unrestricted in
9584+ intervals)
95839585 </para>
95849586
95859587<screen>
@@ -9614,7 +9616,7 @@ SELECT EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
96149616 <listitem>
96159617 <para>
96169618 The <acronym>ISO</acronym> 8601 week-numbering year that the date
9617- falls in (not applicable to intervals)
9619+ falls in
96189620 </para>
96199621
96209622<screen>
@@ -9631,9 +9633,6 @@ SELECT EXTRACT(ISOYEAR FROM DATE '2006-01-02');
96319633 different from the Gregorian year. See the <literal>week</literal>
96329634 field for more information.
96339635 </para>
9634- <para>
9635- This field is not available in PostgreSQL releases prior to 8.3.
9636- </para>
96379636 </listitem>
96389637 </varlistentry>
96399638
@@ -9642,7 +9641,7 @@ SELECT EXTRACT(ISOYEAR FROM DATE '2006-01-02');
96429641 <listitem>
96439642 <para>
96449643 The <firstterm>Julian Date</firstterm> corresponding to the
9645- date or timestamp (not applicable to intervals) . Timestamps
9644+ date or timestamp. Timestamps
96469645 that are not local midnight result in a fractional value. See
96479646 <xref linkend="datetime-julian-dates"/> for more information.
96489647 </para>
@@ -9675,12 +9674,15 @@ SELECT EXTRACT(MICROSECONDS FROM TIME '17:12:28.5');
96759674 <term><literal>millennium</literal></term>
96769675 <listitem>
96779676 <para>
9678- The millennium
9677+ The millennium; for <type>interval</type> values, the year field
9678+ divided by 1000
96799679 </para>
96809680
96819681<screen>
96829682SELECT EXTRACT(MILLENNIUM FROM TIMESTAMP '2001-02-16 20:38:40');
96839683<lineannotation>Result: </lineannotation><computeroutput>3</computeroutput>
9684+ SELECT EXTRACT(MILLENNIUM FROM INTERVAL '2001 years');
9685+ <lineannotation>Result: </lineannotation><computeroutput>2</computeroutput>
96849686</screen>
96859687
96869688 <para>
@@ -9723,18 +9725,16 @@ SELECT EXTRACT(MINUTE FROM TIMESTAMP '2001-02-16 20:38:40');
97239725 <term><literal>month</literal></term>
97249726 <listitem>
97259727 <para>
9726- For <type>timestamp</type> values, thenumber of themonth
9727- within the year (1–12) ; for <type>interval</type> values,
9728- the number of months, modulo 12 (0–11)
9728+ The number of themonth within theyear (1–12);
9729+ for <type>interval</type> values, the number of months modulo 12
9730+ (0–11)
97299731 </para>
97309732
97319733<screen>
97329734SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-16 20:38:40');
97339735<lineannotation>Result: </lineannotation><computeroutput>2</computeroutput>
9734-
97359736SELECT EXTRACT(MONTH FROM INTERVAL '2 years 3 months');
97369737<lineannotation>Result: </lineannotation><computeroutput>3</computeroutput>
9737-
97389738SELECT EXTRACT(MONTH FROM INTERVAL '2 years 13 months');
97399739<lineannotation>Result: </lineannotation><computeroutput>1</computeroutput>
97409740</screen>
@@ -9765,7 +9765,6 @@ SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');
97659765<screen>
97669766SELECT EXTRACT(SECOND FROM TIMESTAMP '2001-02-16 20:38:40');
97679767<lineannotation>Result: </lineannotation><computeroutput>40.000000</computeroutput>
9768-
97699768SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
97709769<lineannotation>Result: </lineannotation><computeroutput>28.500000</computeroutput>
97719770</screen>
@@ -9847,6 +9846,20 @@ SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40');
98479846 </variablelist>
98489847 </para>
98499848
9849+ <para>
9850+ When processing an <type>interval</type> value,
9851+ the <function>extract</function> function produces field values that
9852+ match the interpretation used by the interval output function. This
9853+ can produce surprising results if one starts with a non-normalized
9854+ interval representation, for example:
9855+ <screen>
9856+ SELECT INTERVAL '80 minutes';
9857+ <lineannotation>Result: </lineannotation><computeroutput>01:20:00</computeroutput>
9858+ SELECT EXTRACT(MINUTES FROM INTERVAL '80 minutes');
9859+ <lineannotation>Result: </lineannotation><computeroutput>20</computeroutput>
9860+ </screen>
9861+ </para>
9862+
98509863 <note>
98519864 <para>
98529865 When the input value is +/-Infinity, <function>extract</function> returns
@@ -9884,7 +9897,6 @@ date_part('<replaceable>field</replaceable>', <replaceable>source</replaceable>)
98849897<screen>
98859898SELECT date_part('day', TIMESTAMP '2001-02-16 20:38:40');
98869899<lineannotation>Result: </lineannotation><computeroutput>16</computeroutput>
9887-
98889900SELECT date_part('hour', INTERVAL '4 hours 3 minutes');
98899901<lineannotation>Result: </lineannotation><computeroutput>4</computeroutput>
98909902</screen>
@@ -9962,16 +9974,12 @@ date_trunc(<replaceable>field</replaceable>, <replaceable>source</replaceable> [
99629974<screen>
99639975SELECT date_trunc('hour', TIMESTAMP '2001-02-16 20:38:40');
99649976<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 20:00:00</computeroutput>
9965-
99669977SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
99679978<lineannotation>Result: </lineannotation><computeroutput>2001-01-01 00:00:00</computeroutput>
9968-
99699979SELECT date_trunc('day', TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40+00');
99709980<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 00:00:00-05</computeroutput>
9971-
99729981SELECT date_trunc('day', TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40+00', 'Australia/Sydney');
99739982<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 08:00:00-05</computeroutput>
9974-
99759983SELECT date_trunc('hour', INTERVAL '3 days 02:47:33');
99769984<lineannotation>Result: </lineannotation><computeroutput>3 days 02:00:00</computeroutput>
99779985</screen>
@@ -10010,7 +10018,6 @@ date_bin(<replaceable>stride</replaceable>, <replaceable>source</replaceable>, <
1001010018<screen>
1001110019SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-01-01');
1001210020<lineannotation>Result: </lineannotation><computeroutput>2020-02-11 15:30:00</computeroutput>
10013-
1001410021SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-01-01 00:02:30');
1001510022<lineannotation>Result: </lineannotation><computeroutput>2020-02-11 15:32:30</computeroutput>
1001610023</screen>
@@ -10134,10 +10141,8 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
1013410141<screen>
1013510142SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'America/Denver';
1013610143<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 19:38:40-08</computeroutput>
10137-
1013810144SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver';
1013910145<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 18:38:40</computeroutput>
10140-
1014110146SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago';
1014210147<lineannotation>Result: </lineannotation><computeroutput>2001-02-16 05:38:40</computeroutput>
1014310148</screen>
@@ -10212,16 +10217,12 @@ LOCALTIMESTAMP(<replaceable>precision</replaceable>)
1021210217<screen>
1021310218SELECT CURRENT_TIME;
1021410219<lineannotation>Result: </lineannotation><computeroutput>14:39:53.662522-05</computeroutput>
10215-
1021610220SELECT CURRENT_DATE;
1021710221<lineannotation>Result: </lineannotation><computeroutput>2019-12-23</computeroutput>
10218-
1021910222SELECT CURRENT_TIMESTAMP;
1022010223<lineannotation>Result: </lineannotation><computeroutput>2019-12-23 14:39:53.662522-05</computeroutput>
10221-
1022210224SELECT CURRENT_TIMESTAMP(2);
1022310225<lineannotation>Result: </lineannotation><computeroutput>2019-12-23 14:39:53.66-05</computeroutput>
10224-
1022510226SELECT LOCALTIMESTAMP;
1022610227<lineannotation>Result: </lineannotation><computeroutput>2019-12-23 14:39:53.662522</computeroutput>
1022710228</screen>