Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using [0,1] versus ["Y","N"] versus ["T","F"] in a logical/boolean database field?

Just out of curiosity and lack of a definite answer...

I was just looking at some data that is sent from a 3rd party to us, and their "Gender" field is a [0,1] denoting either a Female (0) or a Male (1).

Is there any better reason to use [0,1] over ["F","M"]?

Does it depend on the scenario and the intuitiveness between a field and its value?

Data access speeds and/or size constraints?

If the moon is full?


What are the differences in using [0,1] versus ["Y","N"] versus ["T","F"]?
like image 537
CheeseConQueso Avatar asked Dec 15 '09 16:12

CheeseConQueso


People also ask

How do you declare a boolean value in SQL?

You can declare a boolean host variable as follows: EXEC SQL BEGIN DECLARE SECTION; boolean flag; EXEC SQL BEGIN DECLARE SECTION; In the Informix ESQL/C program, the following values are the only valid values that you can assign to boolean host variables: TRUE.

Is there a Boolean data type in SQL?

There is boolean data type in SQL Server. Its values can be TRUE , FALSE or UNKNOWN . However, the boolean data type is only the result of a boolean expression containing some combination of comparison operators (e.g. = , <> , < , >= ) or logical operators (e.g. AND , OR , IN , EXISTS ).

When converting a numeric value to boolean Which of the following values will result in true?

Zero ( 0 ) is converted to FALSE. Any non-zero value is converted to TRUE.


2 Answers

Since sex is not actually binary - there is a continuous range of 'intersex' conditions between male and female, as well as beings with no sex at all - it's best to use a floating-point type. 0 for female (being the default, at least in mammals), 1 for male, with intermediate values for intermediate conditions, and NaN for those with no value.

But remember, this will never be fully applicable, because there is no type for the human heart. Although complex is often a good approximation.

like image 162
Tom Anderson Avatar answered Oct 03 '22 04:10

Tom Anderson


A major advantage is that a column that allows for more than two values can be extended naturally if your assumptions change.

Also, more philosophically, our notions of gender/sexuality are much more fluid than accounted for in a binary field. For instance, I was hired to fix a major government application in Massachusetts when same-sex marriage laws were passed, because lots of assumptions were made about marriage that were later invalidated.

like image 35
John Feminella Avatar answered Oct 03 '22 03:10

John Feminella