boolean over char(1)

Started by Thomas T. Thaiover 23 years ago4 messagesgeneral
Jump to latest
#1Thomas T. Thai
tom@minnesota.com

Is there any advantages of using datatype boolean over char(1)? If there
isn't I think char(1) is more portable across other DBM?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas T. Thai (#1)
Re: boolean over char(1)

"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

#3Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#2)
Re: boolean over char(1)

Also, we do support "char", which is one byte. You need to specify the
quotes when creating the column.

---------------------------------------------------------------------------

Tom Lane wrote:

"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

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#3)
Re: boolean over char(1)

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Also, we do support "char", which is one byte. You need to specify the
quotes when creating the column.

But he's looking for "more standard", which "char" surely is not.

regards, tom lane