Home Explore Blog CI



postgresql

14th chunk of `doc/src/sgml/ref/create_table.sgml`
1854af0aa52e9455d8336e71ad4d43d8770637815a3f91e70000000100000fa5
  constraints are chosen according to the default rules, regardless of
          how the originals were named.  (This behavior avoids possible
          duplicate-name failures for the new indexes.)
         </para>
        </listitem>
       </varlistentry>

       <varlistentry id="sql-createtable-parms-like-opt-statistics">
        <term><literal>INCLUDING STATISTICS</literal></term>
        <listitem>
         <para>
          Extended statistics are copied to the new table.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry id="sql-createtable-parms-like-opt-storage">
        <term><literal>INCLUDING STORAGE</literal></term>
        <listitem>
         <para>
          <literal>STORAGE</literal> settings for the copied column
          definitions will be copied.  The default behavior is to exclude
          <literal>STORAGE</literal> settings, resulting in the copied columns
          in the new table having type-specific default settings.  For more on
          <literal>STORAGE</literal> settings, see <xref
          linkend="storage-toast"/>.
         </para>
        </listitem>
       </varlistentry>

       <varlistentry id="sql-createtable-parms-like-opt-all">
        <term><literal>INCLUDING ALL</literal></term>
        <listitem>
         <para>
          <literal>INCLUDING ALL</literal> is an abbreviated form selecting
          all the available individual options.  (It could be useful to write
          individual <literal>EXCLUDING</literal> clauses after
          <literal>INCLUDING ALL</literal> to select all but some specific
          options.)
         </para>
        </listitem>
       </varlistentry>
      </variablelist>
     </para>

     <para>
      The <literal>LIKE</literal> clause can also be used to copy column
      definitions from views, foreign tables, or composite types.
      Inapplicable options (e.g., <literal>INCLUDING INDEXES</literal> from
      a view) are ignored.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-createtable-parms-constraint">
    <term><literal>CONSTRAINT <replaceable class="parameter">constraint_name</replaceable></literal></term>
    <listitem>
     <para>
      An optional name for a column or table constraint.  If the
      constraint is violated, the constraint name is present in error messages,
      so constraint names like <literal>col must be positive</literal> can be used
      to communicate helpful constraint information to client applications.
      (Double-quotes are needed to specify constraint names that contain spaces.)
      If a constraint name is not specified, the system generates a name.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-createtable-parms-not-null">
    <term><literal>NOT NULL [ NO INHERIT ] </literal></term>
    <listitem>
     <para>
      The column is not allowed to contain null values.
     </para>

     <para>
      A constraint marked with <literal>NO INHERIT</literal> will not propagate to
      child tables.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-createtable-parms-null">
    <term><literal>NULL</literal></term>
    <listitem>
     <para>
      The column is allowed to contain null values. This is the default.
     </para>

     <para>
      This clause is only provided for compatibility with
      non-standard SQL databases.  Its use is discouraged in new
      applications.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-createtable-parms-check">
    <term><literal>CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ] </literal></term>
    <listitem>
     <para>
      The <literal>CHECK</literal> clause specifies an expression producing a
      Boolean result which new or updated rows must satisfy for an
      insert or update operation to succeed.  Expressions evaluating
      to TRUE or UNKNOWN succeed.  Should any row of an insert or
      update operation

Title: CREATE TABLE LIKE Clause Options: Statistics, Storage, ALL, and Constraints
Summary
This section continues explaining options for the `LIKE` clause in `CREATE TABLE`, focusing on including statistics and storage settings. It introduces `INCLUDING ALL` as a shortcut for selecting all available options, with the possibility of excluding specific options afterward. It also clarifies that the `LIKE` clause can copy column definitions from various sources like views and foreign tables, ignoring inapplicable options. The section then describes other parameters such as defining column and table constraints, including NOT NULL constraints (with the option to prevent inheritance), allowing NULL values (discouraged for new applications), and specifying CHECK constraints to ensure data validity.