What are the size implications of storing many booleans in one Postgres table? I'd like to be able to filter on these fields without doing bit manipulation, so I want them to be separate fields.
I found a related question about SQL Server, and the answer was that 8 bit fields indeed only take 1 byte of space (nullability aside). However, the PostgreSQL documentation says:
Writing bit without a length is equivalent to bit(1)
and:
A bit string value requires 1 byte for each group of 8 bits, plus 5 or 8 bytes overhead depending on the length of the string
Does this mean a table with 8 separate BIT columns will take up 40 or more bytes per row? Or will it also only take a single byte for all 8?
CREATE TABLE SomeBits (
b1 BIT,
b2 BIT,
b3 BIT,
b4 BIT,
b5 BIT,
b6 BIT,
b7 BIT,
b8 BIT
)
bitis not aboolean- what is it exactly you are trying to store? A bit or a boolean?BOOLEANdata type.6 > 5is a boolean expression, not a "bit"