We use arrays of booleans - a non-standard Postgres feature - quite frequently for storing permissions and similar data. It’s an elegant way to denormalize potentially scary schemas, as long as your client libraries support them.
We needed a function to count the number of true values across a whole table’s worth of boolean arrays - basically a histogram of how many true values in each array field. I thought it would be useful to share because I use PL/PgSQL so occasionally I always forget how to write it, and examples are useful.
Here’s the code:
You also need an implementation of the inexplicably missing max(integer, integer) function:
To comment on this post, mention me on twitter, or drop me an email.