Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 15c68cd

Browse files
committed
Doc: improve description of IN and row-constructor comparisons.
IN and NOT IN work fine on records and arrays, so just say that they accept "expressions" not "scalar expressions". I think that that phrasing was meant to say that they don't work on set-returning expressions, but that's not the common meaning of "scalar". Revise the description of row-constructor comparisons to make it perhaps a bit less confusing. (This partially reverts some dubious wording changes made by commit f566515.) Per gripe from Ilya Nenashev. Back-patch to supported branches. In HEAD and v16, also drop a NOTE about pre-8.2 behavior, which is hopefully no longer of interest to anybody. Discussion: https://postgr.es/m/168968062460.632.14303906825812821399@wrigleys.postgresql.org
1 parent 3f8c98d commit 15c68cd

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

doc/src/sgml/func.sgml

+14-29
Original file line numberDiff line numberDiff line change
@@ -22127,7 +22127,7 @@ WHERE EXISTS (SELECT 1 FROM tab2 WHERE col2 = tab1.col2);
2212722127

2212822128
<para>
2212922129
The right-hand side is a parenthesized list
22130-
of scalar expressions. The result is <quote>true</quote> if the left-hand expression's
22130+
of expressions. The result is <quote>true</quote> if the left-hand expression's
2213122131
result is equal to any of the right-hand expressions. This is a shorthand
2213222132
notation for
2213322133

@@ -22158,7 +22158,7 @@ OR
2215822158

2215922159
<para>
2216022160
The right-hand side is a parenthesized list
22161-
of scalar expressions. The result is <quote>true</quote> if the left-hand expression's
22161+
of expressions. The result is <quote>true</quote> if the left-hand expression's
2216222162
result is unequal to all of the right-hand expressions. This is a shorthand
2216322163
notation for
2216422164

@@ -22269,26 +22269,24 @@ AND
2226922269
<para>
2227022270
Each side is a row constructor,
2227122271
as described in <xref linkend="sql-syntax-row-constructors"/>.
22272-
The two row values must have the same number of fields.
22273-
Each side is evaluated and they are compared row-wise. Row constructor
22274-
comparisons are allowed when the <replaceable>operator</replaceable> is
22272+
The two row constructors must have the same number of fields.
22273+
The given <replaceable>operator</replaceable> is applied to each pair
22274+
of corresponding fields. (Since the fields could be of different
22275+
types, this means that a different specific operator could be selected
22276+
for each pair.)
22277+
All the selected operators must be members of some B-tree operator
22278+
class, or be the negator of an <literal>=</literal> member of a B-tree
22279+
operator class, meaning that row constructor comparison is only
22280+
possible when the <replaceable>operator</replaceable> is
2227522281
<literal>=</literal>,
2227622282
<literal>&lt;&gt;</literal>,
2227722283
<literal>&lt;</literal>,
2227822284
<literal>&lt;=</literal>,
22279-
<literal>&gt;</literal> or
22280-
<literal>&gt;=</literal>.
22281-
Every row element must be of a type which has a default B-tree operator
22282-
class or the attempted comparison may generate an error.
22285+
<literal>&gt;</literal>, or
22286+
<literal>&gt;=</literal>,
22287+
or has semantics similar to one of these.
2228322288
</para>
2228422289

22285-
<note>
22286-
<para>
22287-
Errors related to the number or types of elements might not occur if
22288-
the comparison is resolved using earlier columns.
22289-
</para>
22290-
</note>
22291-
2229222290
<para>
2229322291
The <literal>=</literal> and <literal>&lt;&gt;</literal> cases work slightly differently
2229422292
from the others. Two rows are considered
@@ -22309,19 +22307,6 @@ AND
2230922307
considered.
2231022308
</para>
2231122309

22312-
<note>
22313-
<para>
22314-
Prior to <productname>PostgreSQL</productname> 8.2, the
22315-
<literal>&lt;</literal>, <literal>&lt;=</literal>, <literal>&gt;</literal> and <literal>&gt;=</literal>
22316-
cases were not handled per SQL specification. A comparison like
22317-
<literal>ROW(a,b) &lt; ROW(c,d)</literal>
22318-
was implemented as
22319-
<literal>a &lt; c AND b &lt; d</literal>
22320-
whereas the correct behavior is equivalent to
22321-
<literal>a &lt; c OR (a = c AND b &lt; d)</literal>.
22322-
</para>
22323-
</note>
22324-
2232522310
<synopsis>
2232622311
<replaceable>row_constructor</replaceable> IS DISTINCT FROM <replaceable>row_constructor</replaceable>
2232722312
</synopsis>

0 commit comments

Comments
 (0)