List:General Discussion« Previous MessageNext Message »
From:Thalis A. Kalfigopoulos Date:March 1 2001 6:39pm
Subject:Re: Antwort: boolean type
View as plain text  
> > Is there a boolean field type (Yes/No; True/False, 1/0)  in MySQL or what is
> > closest to the boolean type
> 
> ShortInt: 0 == FALSE, <> 0 == TRUE
> That's how I do it anyway.
> 
> Or maybe combine multiple bool fields to one and use binary logic.


Or quoting from http://www.bitbybit.dk/mysqlfaq/faq.html

Q: create a column of type BOOLEAN?

MySQL does not have a boolean type per se. The usual way to create a boolean value, is to
use the ENUM type:
mysql> CREATE TABLE truths 
	-> (answer ENUM('true','false') NOT NULL);

(don't forget the NOT NULL clause, or you end up having not two, but three legal values
for the field.)

You can also use the following hack to define a field which can contain only one of two
values, namely the empty string ("") or NULL:

mysql> CREATE TABLE truths 
	-> (answer CHAR(0));

The special beauty of the second example is that the data in the field only occupies one
bit, as opposed to an ENUM field, which always occupies at least a byte. However, you get
to do quite a bit of encoding and decoding of these values on your front end...

regards,
thalis

Thread
boolean typeBlaz Grapar1 Mar
  • Re: boolean typeRobert Vetter1 Mar
Antwort: boolean typealexander.skwar1 Mar
  • Re: Antwort: boolean typeThalis A. Kalfigopoulos1 Mar
    • Re: Antwort: boolean typeRobert Vetter2 Mar