Re: bit varying(512) vs bytea(64)

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "TJ O'Donnell" <tjo(at)acm(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: bit varying(512) vs bytea(64)
Date: 2005-03-22 13:04:25
Message-ID: 20050322130425.GA47884@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 21, 2005 at 12:39:09PM -0800, TJ O'Donnell wrote:

> I have N-bit data pairs. I want to write a c-language function
> which compares bits set in each. N is typically 512, but could be other.
> I can store this as bit varying(512) or bytea(64). I can't decide which.
> Here are the questions that concern me.
> 1) will each take the same storage?

Bit strings takes 8 bytes + 1 byte for each 8 bits (or fraction
thereof) of data; bytea takes 4 bytes + 1 byte for each byte of data.
You can find the structure definition for bit strings (VarBit) in
<server/utils/varbit.h>; bytea is just a typedef for struct varlena.

> 2) can I pass bit varying data to a c-language function? I can't find any
> docs or examples of that.

See src/backend/utils/adt/varbit.c in the PostgreSQL source code.

> 3) are bit strings stored as actual bits or as character strings of 0 and 1?

Actual bits, so manipulating the data in C should be the same for
both types. Bit strings take an extra 4 bytes of storage, but if
that doesn't matter then you might want to consider which type would
be easier to manipulate in SQL (bytea functions vs. bit string
functions).

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-03-22 13:16:03 Re: Constraint problem
Previous Message John DeSoi 2005-03-22 12:48:01 Re: grant problem