Re: boolean over char(1)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: boolean over char(1)
Дата
Msg-id 11576.1041629241@sss.pgh.pa.us
обсуждение исходный текст
Ответ на boolean over char(1)  ("Thomas T. Thai" <tom@minnesota.com>)
Ответы Re: boolean over char(1)  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-general
"Thomas T. Thai" <tom@minnesota.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

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Field with default not being set on copy from.
Следующее
От: "culley harrelson"
Дата:
Сообщение: example table functions?