diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2021-03-23 08:45:51 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2021-03-23 10:13:58 +0100 |
commit | a6715af1e72da289474011be1e2d536f991eda34 (patch) | |
tree | 48ae8ef2c5c858baf43611b8a65c4ec22cbe47bf /doc/src | |
parent | 5aed6a1fc214913de9ac69c1717dc64a2483e16d (diff) | |
download | postgresql-a6715af1e72da289474011be1e2d536f991eda34.tar.gz postgresql-a6715af1e72da289474011be1e2d536f991eda34.zip |
Add bit_count SQL function
This function for bit and bytea counts the set bits in the bit or byte
string. Internally, we use the existing popcount functionality.
For the name, after some discussion, we settled on bit_count, which
also exists with this meaning in MySQL, Java, and Python.
Author: David Fetter <david@fetter.org>
Discussion: https://www.postgresql.org/message-id/flat/20201230105535.GJ13234@fetter.org
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/func.sgml | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 68fe6a95b49..1d3429fbd9c 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -4013,6 +4013,28 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three'); <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>31</returnvalue> + </para></entry> + </row> + + <row> + <entry role="func_table_entry"><para role="func_signature"> + <indexterm> <primary>btrim</primary> </indexterm> <function>btrim</function> ( <parameter>bytes</parameter> <type>bytea</type>, @@ -4717,6 +4739,24 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three'); <row> <entry role="func_table_entry"><para role="func_signature"> <indexterm> + <primary>bit_count</primary> + </indexterm> + <function>bit_count</function> ( <type>bit</type> ) + <returnvalue>bigint</returnvalue> + </para> + <para> + Returns the number of bits set in the bit string (also known as + <quote>popcount</quote>). + </para> + <para> + <literal>bit_count(B'10111')</literal> + <returnvalue>4</returnvalue> + </para></entry> + </row> + + <row> + <entry role="func_table_entry"><para role="func_signature"> + <indexterm> <primary>bit_length</primary> </indexterm> <function>bit_length</function> ( <type>bit</type> ) |