Re: bit varying(512) vs bytea(64) - Mailing list pgsql-general

From Michael Fuhr
Subject Re: bit varying(512) vs bytea(64)
Date
Msg-id 20050322130425.GA47884@winnie.fuhr.org
Whole thread Raw
In response to bit varying(512) vs bytea(64)  (TJ O'Donnell <tjo@acm.org>)
List 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/

pgsql-general by date:

Previous
From: John DeSoi
Date:
Subject: Re: grant problem
Next
From: Bruno Wolff III
Date:
Subject: Re: grant problem