Home Explore Blog CI



postgresql

14th chunk of `doc/src/sgml/syntax.sgml`
db7b7da8c37591fbd7f5d2ef49f9ebcfb910ee66eb2d6e6f0000000100000faf
 colwidth="2*"/>
     <thead>
      <row>
       <entry>Operator/Element</entry>
       <entry>Associativity</entry>
       <entry>Description</entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry><token>.</token></entry>
       <entry>left</entry>
       <entry>table/column name separator</entry>
      </row>

      <row>
       <entry><token>::</token></entry>
       <entry>left</entry>
       <entry><productname>PostgreSQL</productname>-style typecast</entry>
      </row>

      <row>
       <entry><token>[</token> <token>]</token></entry>
       <entry>left</entry>
       <entry>array element selection</entry>
      </row>

      <row>
       <entry><token>+</token> <token>-</token></entry>
       <entry>right</entry>
       <entry>unary plus, unary minus</entry>
      </row>

      <row>
       <entry><token>COLLATE</token></entry>
       <entry>left</entry>
       <entry>collation selection</entry>
      </row>

      <row>
       <entry><token>AT</token></entry>
       <entry>left</entry>
       <entry><literal>AT TIME ZONE</literal>, <literal>AT LOCAL</literal></entry>
      </row>

      <row>
       <entry><token>^</token></entry>
       <entry>left</entry>
       <entry>exponentiation</entry>
      </row>

      <row>
       <entry><token>*</token> <token>/</token> <token>%</token></entry>
       <entry>left</entry>
       <entry>multiplication, division, modulo</entry>
      </row>

      <row>
       <entry><token>+</token> <token>-</token></entry>
       <entry>left</entry>
       <entry>addition, subtraction</entry>
      </row>

      <row>
       <entry>(any other operator)</entry>
       <entry>left</entry>
       <entry>all other native and user-defined operators</entry>
      </row>

      <row>
       <entry><token>BETWEEN</token> <token>IN</token> <token>LIKE</token> <token>ILIKE</token> <token>SIMILAR</token></entry>
       <entry></entry>
       <entry>range containment, set membership, string matching</entry>
      </row>

      <row>
       <entry><token>&lt;</token> <token>&gt;</token> <token>=</token> <token>&lt;=</token> <token>&gt;=</token> <token>&lt;&gt;</token>
</entry>
       <entry></entry>
       <entry>comparison operators</entry>
      </row>

      <row>
       <entry><token>IS</token> <token>ISNULL</token> <token>NOTNULL</token></entry>
       <entry></entry>
       <entry><literal>IS TRUE</literal>, <literal>IS FALSE</literal>, <literal>IS
       NULL</literal>, <literal>IS DISTINCT FROM</literal>, etc.</entry>
      </row>

      <row>
       <entry><token>NOT</token></entry>
       <entry>right</entry>
       <entry>logical negation</entry>
      </row>

      <row>
       <entry><token>AND</token></entry>
       <entry>left</entry>
       <entry>logical conjunction</entry>
      </row>

      <row>
       <entry><token>OR</token></entry>
       <entry>left</entry>
       <entry>logical disjunction</entry>
      </row>
     </tbody>
    </tgroup>
   </table>

   <para>
    Note that the operator precedence rules also apply to user-defined
    operators that have the same names as the built-in operators
    mentioned above.  For example, if you define a
    <quote>+</quote> operator for some custom data type it will have
    the same precedence as the built-in <quote>+</quote> operator, no
    matter what yours does.
   </para>

   <para>
    When a schema-qualified operator name is used in the
    <literal>OPERATOR</literal> syntax, as for example in:
<programlisting>
SELECT 3 OPERATOR(pg_catalog.+) 4;
</programlisting>
    the <literal>OPERATOR</literal> construct is taken to have the default precedence
    shown in <xref linkend="sql-precedence-table"/> for
    <quote>any other operator</quote>.  This is true no matter
    which specific operator appears inside <literal>OPERATOR()</literal>.
   </para>

   <note>
    <para>
     <productname>PostgreSQL</productname> versions before 9.5 used slightly different
     operator precedence rules.  In particular, <token>&lt;=</token>

Title: PostgreSQL Operator Precedence Table
Summary
This section presents a table outlining the precedence and associativity of operators in PostgreSQL, from highest to lowest. The table includes operators and elements like the table/column name separator (.), PostgreSQL-style typecast (::), array element selection ([]), unary plus/minus (+/-), collation selection (COLLATE), AT TIME ZONE/AT LOCAL (AT), exponentiation (^), multiplication/division/modulo (*, /, %), addition/subtraction (+/-), other native and user-defined operators, range containment/set membership/string matching (BETWEEN, IN, LIKE, ILIKE, SIMILAR), comparison operators (<, >, =, <=, >=, <>), IS TRUE/FALSE/NULL/DISTINCT FROM (IS, ISNULL, NOTNULL), logical negation (NOT), logical conjunction (AND), and logical disjunction (OR). User-defined operators share the precedence of built-in operators with the same name. The OPERATOR syntax defaults to the precedence of 'any other operator'.