Home Explore Blog CI



postgresql

13th chunk of `doc/src/sgml/syntax.sgml`
d4d53a7449d747332cafe9d4788b849370921467a42268b50000000100000fb6
 (<literal>;</literal>) terminates an SQL command.
      It cannot appear anywhere within a command, except within a
      string constant or quoted identifier.
     </para>
    </listitem>

    <listitem>
     <para>
      The colon (<literal>:</literal>) is used to select
      <quote>slices</quote> from arrays. (See <xref
      linkend="arrays"/>.)  In certain SQL dialects (such as Embedded
      SQL), the colon is used to prefix variable names.
     </para>
    </listitem>

    <listitem>
     <para>
      The asterisk (<literal>*</literal>) is used in some contexts to denote
      all the fields of a table row or composite value.  It also
      has a special meaning when used as the argument of an
      aggregate function, namely that the aggregate does not require
      any explicit parameter.
     </para>
    </listitem>

    <listitem>
     <para>
      The period (<literal>.</literal>) is used in numeric
      constants, and to separate schema, table, and column names.
     </para>
    </listitem>
   </itemizedlist>

   </para>
  </sect2>

  <sect2 id="sql-syntax-comments">
   <title>Comments</title>

   <indexterm zone="sql-syntax-comments">
    <primary>comment</primary>
    <secondary sortas="SQL">in SQL</secondary>
   </indexterm>

   <para>
    A comment is a sequence of characters beginning with
    double dashes and extending to the end of the line, e.g.:
<programlisting>
-- This is a standard SQL comment
</programlisting>
   </para>

   <para>
    Alternatively, C-style block comments can be used:
<programlisting>
/* multiline comment
 * with nesting: /* nested block comment */
 */
</programlisting>
    where the comment begins with <literal>/*</literal> and extends to
    the matching occurrence of <literal>*/</literal>. These block
    comments nest, as specified in the SQL standard but unlike C, so that one can
    comment out larger blocks of code that might contain existing block
    comments.
   </para>

   <para>
    A comment is removed from the input stream before further syntax
    analysis and is effectively replaced by whitespace.
   </para>
  </sect2>

  <sect2 id="sql-precedence">
   <title>Operator Precedence</title>

   <indexterm zone="sql-precedence">
    <primary>operator</primary>
    <secondary>precedence</secondary>
   </indexterm>

   <para>
    <xref linkend="sql-precedence-table"/> shows the precedence and
    associativity of the operators in <productname>PostgreSQL</productname>.
    Most operators have the same precedence and are left-associative.
    The precedence and associativity of the operators is hard-wired
    into the parser.
    Add parentheses if you want an expression with multiple operators
    to be parsed in some other way than what the precedence rules imply.
   </para>

   <table id="sql-precedence-table">
    <title>Operator Precedence (highest to lowest)</title>

    <tgroup cols="3">
     <colspec colname="col1" colwidth="2*"/>
     <colspec colname="col2" colwidth="1*"/>
     <colspec colname="col3" 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>

Title: SQL Comments and Operator Precedence
Summary
This section describes the use of the semicolon (;) to terminate SQL commands, with the exception of its presence within string constants or quoted identifiers. It also details the colon (:), asterisk (*), and period (.) characters and their uses in array slicing, referencing table fields, and specifying numeric constants or separating names. The section then explains SQL comments, including single-line comments using double dashes and C-style block comments. Lastly, it outlines operator precedence in PostgreSQL, indicating most operators have the same precedence and are left-associative, while providing a table of operator precedence from highest to lowest.