Home Explore Blog CI



postgresql

54th chunk of `doc/src/sgml/func.sgml`
5349492a68e750f2279cda96f0ebace8e987b509295ee6e80000000100000fa2
 <para>
        <literal>trim(both from '\x1234567890'::bytea, '\x9012'::bytea)</literal>
        <returnvalue>\x345678</returnvalue>
       </para></entry>
      </row>
     </tbody>
    </tgroup>
   </table>

   <para>
    Additional binary string manipulation functions are available and
    are listed in <xref linkend="functions-binarystring-other"/>.  Some
    of them are used internally to implement the
    <acronym>SQL</acronym>-standard string functions listed in <xref
    linkend="functions-binarystring-sql"/>.
   </para>

   <table id="functions-binarystring-other">
    <title>Other Binary String Functions</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Function
       </para>
       <para>
        Description
       </para>
       <para>
        Example(s)
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>bit_count</primary>
        </indexterm>
        <indexterm>
         <primary>popcount</primary>
         <see>bit_count</see>
        </indexterm>
        <function>bit_count</function> ( <parameter>bytes</parameter> <type>bytea</type> )
        <returnvalue>bigint</returnvalue>
       </para>
       <para>
        Returns the number of bits set in the binary string (also known as
        <quote>popcount</quote>).
       </para>
       <para>
        <literal>bit_count('\x1234567890'::bytea)</literal>
        <returnvalue>15</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>crc32</primary>
        </indexterm>
        <function>crc32</function> ( <type>bytea</type> )
        <returnvalue>bigint</returnvalue>
       </para>
       <para>
        Computes the CRC-32 value of the binary string.
       </para>
       <para>
        <literal>crc32('abc'::bytea)</literal>
        <returnvalue>891568578</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>crc32c</primary>
        </indexterm>
        <function>crc32c</function> ( <type>bytea</type> )
        <returnvalue>bigint</returnvalue>
       </para>
       <para>
        Computes the CRC-32C value of the binary string.
       </para>
       <para>
        <literal>crc32c('abc'::bytea)</literal>
        <returnvalue>910901175</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>get_bit</primary>
        </indexterm>
        <function>get_bit</function> ( <parameter>bytes</parameter> <type>bytea</type>,
        <parameter>n</parameter> <type>bigint</type> )
        <returnvalue>integer</returnvalue>
       </para>
       <para>
        Extracts <link linkend="functions-zerobased-note">n'th</link> bit
        from binary string.
       </para>
       <para>
        <literal>get_bit('\x1234567890'::bytea, 30)</literal>
        <returnvalue>1</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>get_byte</primary>
        </indexterm>
        <function>get_byte</function> ( <parameter>bytes</parameter> <type>bytea</type>,
        <parameter>n</parameter> <type>integer</type> )
        <returnvalue>integer</returnvalue>
       </para>
       <para>
        Extracts <link linkend="functions-zerobased-note">n'th</link> byte
        from binary string.
       </para>
       <para>
        <literal>get_byte('\x1234567890'::bytea, 4)</literal>
        <returnvalue>144</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>

Title: Other Binary String Functions: bit_count, crc32, get_bit, get_byte
Summary
This section describes additional binary string manipulation functions including: `bit_count` (counts the number of set bits), `crc32` (computes the CRC-32 value), `crc32c` (computes the CRC-32C value), `get_bit` (extracts a specific bit), and `get_byte` (extracts a specific byte). Each function's syntax, description, and an example are provided.