mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
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
This commit is contained in:
@@ -3440,6 +3440,17 @@ bytea_overlay(bytea *t1, bytea *t2, int sp, int sl)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* bit_count
|
||||
*/
|
||||
Datum
|
||||
bytea_bit_count(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *t1 = PG_GETARG_BYTEA_PP(0);
|
||||
|
||||
PG_RETURN_INT64(pg_popcount(VARDATA_ANY(t1), VARSIZE_ANY_EXHDR(t1)));
|
||||
}
|
||||
|
||||
/*
|
||||
* byteapos -
|
||||
* Return the position of the specified substring.
|
||||
|
||||
Reference in New Issue
Block a user