Re: boolean over char(1)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Thomas T(dot) Thai" <tom(at)minnesota(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: boolean over char(1)
Date: 2003-01-03 21:27:21
Message-ID: 11576.1041629241@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Thomas T. Thai" <tom(at)minnesota(dot)com> writes:
> Is there any advantages of using datatype boolean over char(1)?

boolean fits in 1 byte; char(1) requires 5 bytes (maybe more, depending
on alignment considerations).

boolean will be considerably faster to operate on, being pass-by-value.

char(1) will happily accept values that don't correspond to booleans
(eg, if you use 't' and 'f' to represent booleans in a char(1), what
will you do with 'y' or 'z'?) You could possibly fix that with a
check constraint, but that slows things down still more.

boolean is, um, boolean: it behaves as expected in boolean expressions.
You can't do AND, OR, NOT directly on chars.

> If there isn't I think char(1) is more portable across other DBM?

The boolean datatype is standard in SQL99.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message culley harrelson 2003-01-03 21:43:07 example table functions?
Previous Message Tom Lane 2003-01-03 21:08:25 Re: Field with default not being set on copy from.