aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-04-26 11:50:35 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-04-26 11:50:35 -0400
commit64d617de3c595226804e850b8c8a45517f794932 (patch)
treebd1bdf7e49b093801aa1f7a30a9098f836e58be0
parentd59964999d15be29fcd97544e66780fc5c9f17a9 (diff)
downloadpostgresql-64d617de3c595226804e850b8c8a45517f794932.tar.gz
postgresql-64d617de3c595226804e850b8c8a45517f794932.zip
Doc: document EXTRACT(JULIAN ...), improve Julian Date explanation.
For some reason, the "julian" option for extract()/date_part() has never gotten listed in the manual. Also, while Appendix B mentioned in passing that we don't conform to the usual astronomical definition that a Julian date starts at noon UTC, it was kind of vague about what we do instead. Clarify that, and add an example showing how to get the astronomical definition if you want it. It's been like this for ages, so back-patch to all supported branches. Discussion: https://postgr.es/m/1197050.1619123213@sss.pgh.pa.us
-rw-r--r--doc/src/sgml/datetime.sgml46
-rw-r--r--doc/src/sgml/func.sgml22
2 files changed, 61 insertions, 7 deletions
diff --git a/doc/src/sgml/datetime.sgml b/doc/src/sgml/datetime.sgml
index 2653d620c2e..d9666ebe7d9 100644
--- a/doc/src/sgml/datetime.sgml
+++ b/doc/src/sgml/datetime.sgml
@@ -785,9 +785,6 @@
<indexterm zone="datetime-units-history">
<primary>Gregorian calendar</primary>
</indexterm>
- <indexterm zone="datetime-units-history">
- <primary>Julian date</primary>
- </indexterm>
<para>
The SQL standard states that <quote>Within the definition of a
@@ -890,14 +887,27 @@ $ <userinput>cal 9 1752</userinput>
festivals.
</para>
+ </sect1>
+
+ <sect1 id="datetime-julian-dates">
+ <title>Julian Dates</title>
+
+ <indexterm zone="datetime-julian-dates">
+ <primary>Julian date</primary>
+ </indexterm>
+
<para>
- The <firstterm>Julian Date</firstterm> system is another type of
- calendar, unrelated to the Julian calendar though it is confusingly
+ The <firstterm>Julian Date</firstterm> system is a method for
+ numbering days. It is
+ unrelated to the Julian calendar, though it is confusingly
named similarly to that calendar.
The Julian Date system was invented by the French scholar
Joseph Justus Scaliger (1540-1609)
and probably takes its name from Scaliger's father,
the Italian scholar Julius Caesar Scaliger (1484-1558).
+ </para>
+
+ <para>
In the Julian Date system, each day has a sequential number, starting
from JD 0 (which is sometimes called <emphasis>the</> Julian Date).
JD 0 corresponds to 1 January 4713 BC in the Julian calendar, or
@@ -913,7 +923,31 @@ $ <userinput>cal 9 1752</userinput>
input and output of dates (and also uses Julian dates for some internal
datetime calculations), it does not observe the nicety of having dates
run from noon to noon. <productname>PostgreSQL</> treats a Julian Date
- as running from midnight to midnight.
+ as running from local midnight to local midnight, the same as a normal
+ date.
+ </para>
+
+ <para>
+ This definition does, however, provide a way to obtain the astronomical
+ definition when you need it: do the arithmetic in time
+ zone <literal>UTC-12</literal>. For example,
+<programlisting>
+=&gt; SELECT extract(julian from '2021-06-23 7:00:00-04'::timestamptz at time zone 'UTC-12');
+ date_part
+--------------------
+ 2459389.9583333335
+(1 row)
+=&gt; SELECT extract(julian from '2021-06-23 8:00:00-04'::timestamptz at time zone 'UTC-12');
+ date_part
+-----------
+ 2459390
+(1 row)
+=&gt; SELECT extract(julian from date '2021-06-24');
+ date_part
+-----------
+ 2459390
+(1 row)
+</programlisting>
</para>
</sect1>
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index fa9df4ad1d0..c51354d81df 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -6076,7 +6076,8 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
</row>
<row>
<entry><literal>J</literal></entry>
- <entry>Julian Day (integer days since November 24, 4714 BC at midnight UTC)</entry>
+ <entry>Julian Date (integer days since November 24, 4714 BC at local
+ midnight; see <xref linkend="datetime-julian-dates">)</entry>
</row>
<row>
<entry><literal>Q</literal></entry>
@@ -7730,6 +7731,25 @@ SELECT EXTRACT(ISOYEAR FROM DATE '2006-01-02');
</varlistentry>
<varlistentry>
+ <term><literal>julian</literal></term>
+ <listitem>
+ <para>
+ The <firstterm>Julian Date</firstterm> corresponding to the
+ date or timestamp (not applicable to intervals). Timestamps
+ that are not local midnight result in a fractional value. See
+ <xref linkend="datetime-julian-dates"> for more information.
+ </para>
+
+<screen>
+SELECT EXTRACT(JULIAN FROM DATE '2006-01-01');
+<lineannotation>Result: </lineannotation><computeroutput>2453737</computeroutput>
+SELECT EXTRACT(JULIAN FROM TIMESTAMP '2006-01-01 12:00');
+<lineannotation>Result: </lineannotation><computeroutput>2453737.5</computeroutput>
+</screen>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>microseconds</literal></term>
<listitem>
<para>