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:
@ -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
|
||||
|
Reference in New Issue
Block a user