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

Make extract() do something more reasonable with infinite datetimes.

Historically, extract() just returned zero for any case involving an
infinite timestamp[tz] input; even cases in which the unit name was
invalid.  This is not very sensible.  Instead, return infinity or
-infinity as appropriate when the requested field is one that is
monotonically increasing (e.g, year, epoch), or NULL when it is not
(e.g., day, hour).  Also, throw the expected errors for bad unit names.

BACKWARDS INCOMPATIBLE CHANGE

Vitaly Burovoy, reviewed by Vik Fearing
This commit is contained in:
Tom Lane
2016-01-21 22:26:20 -05:00
parent d9b9289c83
commit 647d87c56a
4 changed files with 405 additions and 12 deletions

View File

@ -7521,6 +7521,17 @@ SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40');
</variablelist>
</para>
<note>
<para>
When the input value is +/-Infinity, <function>extract</> returns
+/-Infinity for monotonically-increasing fields (<literal>epoch</>,
<literal>julian</>, <literal>year</>, <literal>isoyear</>,
<literal>decade</>, <literal>century</>, and <literal>millennium</>).
For other fields, NULL is returned. <productname>PostgreSQL</>
versions before 9.6 returned zero for all cases of infinite input.
</para>
</note>
<para>
The <function>extract</function> function is primarily intended
for computational processing. For formatting date/time values for