Efficient Boolean Storage

From: "Chris White" <cwhite(at)at-sd(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Efficient Boolean Storage
Date: 2002-12-04 01:06:35
Message-ID: 000901c29b31$64fb2a80$9d03a8c0@archnet2.atgsd.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I need to store many (e.g. 30) booleans and am wondering what is the
most efficient way to store them. I can think of four options.

Option 1...Use 'bool' data type
No good since each value will require 1 byte rather than 1 bit.

Option 2...Use 'bit string' data type
Good since bit status is visible e.g. 0001000110
Questionable...How much storage used? Storage = 1 byte per bit? Or
Storage = # of bits rounded to nearest byte?

Option 3...Use sets of 'char'
Good since compact. Storage is known...8 booleans = 8 bits = 1 byte
Bad since less obvious to casual database viewer.

Option 4...Use individual 'bit' data types for each Boolean
Good since obvious to casual database viewer.
Questionable...Probably uses 1 byte per bit.

Thanks in advance for your help. I'm new to PostgreSQL. Yet, I'm
architecting a database where storage space is at a premium.

- Chris

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2002-12-04 01:57:02 Re: Postgresql -- initial impressions and comments
Previous Message Joseph Shraibman 2002-12-04 01:01:56 set in transaction