Skip to content

Commit 319f4d5

Browse files
committed
Doc: spell out comparison behaviors for the date/time types.
The behavior of cross-type comparisons among date/time data types was not really explained anywhere. You could probably infer it if you recognized the applicability of comments elsewhere about datatype conversions, but it seems worthy of explicit documentation. Per bug #16797 from Dana Burd. Discussion: https://postgr.es/m/16797-f264b0b980b53b8b@postgresql.org
1 parent 0918667 commit 319f4d5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

doc/src/sgml/func.sgml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8190,14 +8190,30 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
81908190
linkend="datatype-datetime"/>.
81918191
</para>
81928192

8193+
<para>
8194+
In addition, the usual comparison operators shown in
8195+
<xref linkend="functions-comparison-op-table"/> are available for the
8196+
date/time types. Dates and timestamps (with or without time zone) are
8197+
all comparable, while times (with or without time zone) and intervals
8198+
can only be compared to other values of the same data type. When
8199+
comparing a timestamp without time zone to a timestamp with time zone,
8200+
the former value is assumed to be given in the time zone specified by
8201+
the <xref linkend="guc-timezone"/> configuration parameter, and is
8202+
rotated to UTC for comparison to the latter value (which is already
8203+
in UTC internally). Similarly, a date value is assumed to represent
8204+
midnight in the <varname>TimeZone</varname> zone when comparing it
8205+
to a timestamp.
8206+
</para>
8207+
81938208
<para>
81948209
All the functions and operators described below that take <type>time</type> or <type>timestamp</type>
81958210
inputs actually come in two variants: one that takes <type>time with time zone</type> or <type>timestamp
81968211
with time zone</type>, and one that takes <type>time without time zone</type> or <type>timestamp without time zone</type>.
81978212
For brevity, these variants are not shown separately. Also, the
81988213
<literal>+</literal> and <literal>*</literal> operators come in commutative pairs (for
8199-
example both date + integer and integer + date); we show only one of each
8200-
such pair.
8214+
example both <type>date</type> <literal>+</literal> <type>integer</type>
8215+
and <type>integer</type> <literal>+</literal> <type>date</type>); we show
8216+
only one of each such pair.
82018217
</para>
82028218

82038219
<table id="operators-datetime-table">

0 commit comments

Comments
 (0)