Home Explore Blog CI



postgresql

46th chunk of `doc/src/sgml/datatype.sgml`
0510fe66373b9b69039d85bf69d8cafc1fe46f92d1b8a9d80000000100000fa0
 <colspec colname="col1" colwidth="1*"/>
      <colspec colname="col2" colwidth="1*"/>
      <colspec colname="col3" colwidth="2*"/>
      <thead>
       <row>
        <entry>Name</entry>
        <entry>Storage Size</entry>
        <entry>Description</entry>
       </row>
      </thead>
      <tbody>

       <row>
        <entry><type>cidr</type></entry>
        <entry>7 or 19 bytes</entry>
        <entry>IPv4 and IPv6 networks</entry>
       </row>

       <row>
        <entry><type>inet</type></entry>
        <entry>7 or 19 bytes</entry>
        <entry>IPv4 and IPv6 hosts and networks</entry>
       </row>

       <row>
        <entry><type>macaddr</type></entry>
        <entry>6 bytes</entry>
        <entry>MAC addresses</entry>
       </row>

       <row>
        <entry><type>macaddr8</type></entry>
        <entry>8 bytes</entry>
        <entry>MAC addresses (EUI-64 format)</entry>
       </row>

      </tbody>
     </tgroup>
    </table>

   <para>
    When sorting <type>inet</type> or <type>cidr</type> data types,
    IPv4 addresses will always sort before IPv6 addresses, including
    IPv4 addresses encapsulated or mapped to IPv6 addresses, such as
    ::10.2.3.4 or ::ffff:10.4.3.2.
   </para>


   <sect2 id="datatype-inet">
    <title><type>inet</type></title>

    <indexterm>
     <primary>inet (data type)</primary>
    </indexterm>

    <para>
     The <type>inet</type> type holds an IPv4 or IPv6 host address, and
     optionally its subnet, all in one field.
     The subnet is represented by the number of network address bits
     present in the host address (the
     <quote>netmask</quote>).  If the netmask is 32 and the address is IPv4,
     then the value does not indicate a subnet, only a single host.
     In IPv6, the address length is 128 bits, so 128 bits specify a
     unique host address.  Note that if you
     want to accept only networks, you should use the
     <type>cidr</type> type rather than <type>inet</type>.
    </para>

    <para>
      The input format for this type is
      <replaceable class="parameter">address/y</replaceable>
      where
      <replaceable class="parameter">address</replaceable>
      is an IPv4 or IPv6 address and
      <replaceable class="parameter">y</replaceable>
      is the number of bits in the netmask.  If the
      <replaceable class="parameter">/y</replaceable>
      portion is omitted, the
      netmask is taken to be 32 for IPv4 or 128 for IPv6,
      so the value represents
      just a single host.  On display, the
      <replaceable class="parameter">/y</replaceable>
      portion is suppressed if the netmask specifies a single host.
    </para>
   </sect2>

   <sect2 id="datatype-cidr">
    <title><type>cidr</type></title>

    <indexterm>
     <primary>cidr</primary>
    </indexterm>

    <para>
     The <type>cidr</type> type holds an IPv4 or IPv6 network specification.
     Input and output formats follow Classless Internet Domain Routing
     conventions.
     The format for specifying networks is <replaceable
     class="parameter">address/y</replaceable> where <replaceable
     class="parameter">address</replaceable> is the network's lowest
     address represented as an
     IPv4 or IPv6 address, and <replaceable
     class="parameter">y</replaceable> is the number of bits in the netmask.  If
     <replaceable class="parameter">y</replaceable> is omitted, it is calculated
     using assumptions from the older classful network numbering system, except
     it will be at least large enough to include all of the octets
     written in the input.  It is an error to specify a network address
     that has bits set to the right of the specified netmask.
    </para>

    <para>
     <xref linkend="datatype-net-cidr-table"/> shows some examples.
    </para>

     <table id="datatype-net-cidr-table">
      <title><type>cidr</type> Type Input Examples</title>
      <tgroup cols="3">
       <thead>
        <row>
         <entry><type>cidr</type> Input</entry>
     

Title: Network Address Data Types
Summary
This section describes the data types used to store network addresses in PostgreSQL, including inet and cidr. The inet type holds an IPv4 or IPv6 host address and optionally its subnet, while the cidr type holds a network specification. The input and output formats for these types are discussed, as well as examples of how to use them to represent networks and host addresses.