Home Explore Blog CI



postgresql

49th chunk of `doc/src/sgml/datatype.sgml`
895e2e5e2edf5abe2ae759c6bfd43c45f507dd31a6a7f5870000000100000fc0
 canonical LSB
     order.
    </para>

    <para>
     The remaining five input formats are not part of any standard.
    </para>
   </sect2>

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

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

    <indexterm>
     <primary>MAC address (EUI-64 format)</primary>
     <see>macaddr</see>
    </indexterm>

    <para>
     The <type>macaddr8</type> type stores MAC addresses in EUI-64
     format, known for example from Ethernet card hardware addresses
     (although MAC addresses are used for other purposes as well).
     This type can accept both 6 and 8 byte length MAC addresses
     and stores them in 8 byte length format.  MAC addresses given
     in 6 byte format will be stored in 8 byte length format with the
     4th and 5th bytes set to FF and FE, respectively.

     Note that IPv6 uses a modified EUI-64 format where the 7th bit
     should be set to one after the conversion from EUI-48.  The
     function <function>macaddr8_set7bit</function> is provided to make this
     change.

     Generally speaking, any input which is comprised of pairs of hex
     digits (on byte boundaries), optionally separated consistently by
     one of <literal>':'</literal>, <literal>'-'</literal> or <literal>'.'</literal>, is
     accepted.  The number of hex digits must be either 16 (8 bytes) or
     12 (6 bytes).  Leading and trailing whitespace is ignored.

     The following are examples of input formats that are accepted:

     <simplelist>
      <member><literal>'08:00:2b:01:02:03:04:05'</literal></member>
      <member><literal>'08-00-2b-01-02-03-04-05'</literal></member>
      <member><literal>'08002b:0102030405'</literal></member>
      <member><literal>'08002b-0102030405'</literal></member>
      <member><literal>'0800.2b01.0203.0405'</literal></member>
      <member><literal>'0800-2b01-0203-0405'</literal></member>
      <member><literal>'08002b01:02030405'</literal></member>
      <member><literal>'08002b0102030405'</literal></member>
     </simplelist>

     These examples all specify the same address.  Upper and
     lower case is accepted for the digits
     <literal>a</literal> through <literal>f</literal>.  Output is always in the
     first of the forms shown.
    </para>

    <para>
     The last six input formats shown above are not part of any standard.
    </para>

    <para>
     To convert a traditional 48 bit MAC address in EUI-48 format to
     modified EUI-64 format to be included as the host portion of an
     IPv6 address, use <function>macaddr8_set7bit</function> as shown:

<programlisting>
SELECT macaddr8_set7bit('08:00:2b:01:02:03');
<computeroutput>
    macaddr8_set7bit
-------------------------
 0a:00:2b:ff:fe:01:02:03
(1 row)
</computeroutput>
</programlisting>

    </para>

   </sect2>

  </sect1>

  <sect1 id="datatype-bit">
   <title>Bit String Types</title>

   <indexterm zone="datatype-bit">
    <primary>bit string</primary>
    <secondary>data type</secondary>
   </indexterm>

   <para>
    Bit strings are strings of 1's and 0's.  They can be used to store
    or visualize bit masks.  There are two SQL bit types:
    <type>bit(<replaceable>n</replaceable>)</type> and <type>bit
    varying(<replaceable>n</replaceable>)</type>, where
    <replaceable>n</replaceable> is a positive integer.
   </para>

   <para>
    <type>bit</type> type data must match the length
    <replaceable>n</replaceable> exactly; it is an error to attempt to
    store shorter or longer bit strings.  <type>bit varying</type> data is
    of variable length up to the maximum length
    <replaceable>n</replaceable>; longer strings will be rejected.
    Writing <type>bit</type> without a length is equivalent to
    <literal>bit(1)</literal>, while <type>bit varying</type> without a length
    specification means unlimited length.
   </para>

   <note>
    <para>
     If one explicitly casts a bit-string value to
     <type>bit(<replaceable>n</replaceable>)</type>,

Title: Data Types: MACADDR8 and Bit Strings
Summary
This section discusses the MACADDR8 data type for storing MAC addresses in EUI-64 format, including input formats, conversion rules, and examples. It also introduces bit string types, such as bit(n) and bit varying(n), which can be used to store or visualize bit masks, with varying length and error handling for mismatched lengths.