Boolean type storage format
Boolean type storage format
От:
"Alexander Gataric" <gataric@usa.net>
Дата:
What is the data physically stored as for boolean type? I know that it is one byte but is it char, int, or something else?
Sent from my smartphone
Sent from my smartphone
Re: Boolean type storage format
От:
Raghavendra <raghavendra.rao@enterprisedb.com>
Дата:
On Wed, Oct 31, 2012 at 8:52 PM, Alexander Gataric <gataric@usa.net> wrote:
What is the data physically stored as for boolean type? I know that it is one byte but is it char, int, or something else?
False represented by zero bytes and True by 1 byte with value 1.
Re: Boolean type storage format
От:
Mike Christensen <mike@kitchenpc.com>
Дата:
It would also matter what columns were next to it, correct?
For example, if you had 4 bools in a row, that could also be 1 byte..
On Wed, Oct 31, 2012 at 11:08 AM, Raghavendra <raghavendra.rao@enterprisedb.com> wrote:
On Wed, Oct 31, 2012 at 8:52 PM, Alexander Gataric <gataric@usa.net> wrote:What is the data physically stored as for boolean type? I know that it is one byte but is it char, int, or something else?False represented by zero bytes and True by 1 byte with value 1.
Re: Boolean type storage format
От:
Craig Ringer <ringerc@ringerc.id.au>
Дата:
On 11/01/2012 02:25 AM, Mike Christensen wrote:
> It would also matter what columns were next to it, correct?
It doesn't look like PostgreSQL packs booleans. It still matters what's
next to it because of the alignment requirements of other data types,
but you still have a minimum of one byte per boolean. See:
regress=> SELECT pg_column_size( ROW('t'::boolean) );
pg_column_size
----------------
25
(1 row)
regress=> SELECT pg_column_size( ROW('t'::boolean, 't'::boolean) );
pg_column_size
----------------
26
(1 row)
regress=> SELECT pg_column_size( ROW('t'::boolean, 't'::boolean,
'f'::boolean, 't'::boolean) );
pg_column_size
----------------
28
(1 row)
--
Craig Ringer
Re: Boolean type storage format
От:
Marti Raudsepp <marti@juffo.org>
Дата:
On Wed, Oct 31, 2012 at 8:08 PM, Raghavendra wrote: > False represented by zero bytes and True by 1 byte with value 1. This is not true AFAIK. Both boolean TRUE and FALSE values require 1 byte. A NULL value is zero bytes (though it still consumes 1 bit in the null bitmap). This is true for all types, not just boolean. Regards, Marti