Commit c0dc44eb authored by Tom Lane's avatar Tom Lane

A bit more editing for collation documentation.

parent d367d41d
...@@ -1257,6 +1257,12 @@ SELECT 3 OPERATOR(pg_catalog.+) 4; ...@@ -1257,6 +1257,12 @@ SELECT 3 OPERATOR(pg_catalog.+) 4;
</para> </para>
</listitem> </listitem>
<listitem>
<para>
A collation expression
</para>
</listitem>
<listitem> <listitem>
<para> <para>
A scalar subquery A scalar subquery
...@@ -1898,8 +1904,8 @@ CAST ( <replaceable>expression</replaceable> AS <replaceable>type</replaceable> ...@@ -1898,8 +1904,8 @@ CAST ( <replaceable>expression</replaceable> AS <replaceable>type</replaceable>
</note> </note>
</sect2> </sect2>
<sect2 id="sql-syntax-collate-clause"> <sect2 id="sql-syntax-collate-exprs">
<title>COLLATE Clause</title> <title>Collation Expressions</title>
<indexterm> <indexterm>
<primary>COLLATE</primary> <primary>COLLATE</primary>
...@@ -1925,7 +1931,7 @@ CAST ( <replaceable>expression</replaceable> AS <replaceable>type</replaceable> ...@@ -1925,7 +1931,7 @@ CAST ( <replaceable>expression</replaceable> AS <replaceable>type</replaceable>
</para> </para>
<para> <para>
The two typical uses of the <literal>COLLATE</literal> clause are The two common uses of the <literal>COLLATE</literal> clause are
overriding the sort order in an <literal>ORDER BY</> clause, for overriding the sort order in an <literal>ORDER BY</> clause, for
example: example:
<programlisting> <programlisting>
...@@ -1934,15 +1940,28 @@ SELECT a, b, c FROM tbl WHERE ... ORDER BY a COLLATE "C"; ...@@ -1934,15 +1940,28 @@ SELECT a, b, c FROM tbl WHERE ... ORDER BY a COLLATE "C";
and overriding the collation of a function or operator call that and overriding the collation of a function or operator call that
has locale-sensitive results, for example: has locale-sensitive results, for example:
<programlisting> <programlisting>
SELECT * FROM tbl WHERE a > 'foo' COLLATE "C"; SELECT * FROM tbl WHERE a &gt; 'foo' COLLATE "C";
</programlisting>
Note that in the latter case the <literal>COLLATE</> clause is
attached to an input argument of the operator we wish to affect.
It doesn't matter which argument of the operator or function call the
<literal>COLLATE</> clause is attached to, because the collation that is
applied by the operator or function is derived by considering all
arguments, and an explicit <literal>COLLATE</> clause will override the
collations of all other arguments. (Attaching non-matching
<literal>COLLATE</> clauses to more than one argument, however, is an
error. For more details see <xref linkend="collation">.)
Thus, this gives the same result as the previous example:
<programlisting>
SELECT * FROM tbl WHERE a COLLATE "C" &gt; 'foo';
</programlisting>
But this is an error:
<programlisting>
SELECT * FROM tbl WHERE (a &gt; 'foo') COLLATE "C";
</programlisting> </programlisting>
In the latter case it doesn't matter which argument of the because it attempts to apply a collation to the result of the
operator of function call the <literal>COLLATE</> clause is <literal>&gt;</> operator, which is of the non-collatable data type
attached to, because the collation that is applied by the operator <type>boolean</>.
or function is derived from all arguments, and
the <literal>COLLATE</> clause will override the collations of all
other arguments. Attaching nonmatching <literal>COLLATE</>
clauses to more than one argument, however, is an error.
</para> </para>
</sect2> </sect2>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment