Glossary Term
Boolean data type
Generalities about Boolean Data Type
- Programming languages like Pascal and Java have a built-in Boolean data type.
- Comparison operators like 'and' are defined to return a Boolean value.
- Conditional and iterative commands are used to test Boolean-valued expressions.
- Some languages like C90 and Lisp represent truth values using other data types.
- Booleans can be implemented as numerical variables with one binary digit or as bit strings of length one.
Boolean Data Type in Programming Languages
- Fortran:
- The first versions of FORTRAN had no logical values or operations.
- FORTRAN IV introduced a Boolean data type, logical literals, and logical operators.
- FORMAT statements in FORTRAN have specific format descriptors for parsing or formatting logical values.
- Later languages like Modula, Ada, and Haskell adopted the Boolean data type derived from FORTRAN.
- FORTRAN uses a BIT(1) representation for Boolean values.
- C, C++, Objective-C, AWK:
- Initial implementations of C did not have a Boolean type, using integers instead.
- ANSI C added enumerated types, allowing programmers to define their own Boolean types.
- Standard C introduced the _Bool type, which can be used with the bool name and true/false constants.
- C++ has a separate bool data type with automatic conversions from scalar and pointer values.
- Objective-C has a separate BOOL data type, but can also use the _Bool type from C.
- PL/I:
- PL/I does not have a Boolean data type.
- Comparison operators in PL/I generate BIT(1) values, with 0B representing false and 1B representing true.
- Operations on PL/I BIT(1) values are performed on each bit.
- The element-expression of an IF statement in PL/I is true if any bit is 1.
- Rexx:
- Rexx does not have a Boolean data type.
- Comparison operators in Rexx generate 0 or 1, with 0 representing false and 1 representing true.
- Rexx operands must be 0 or 1 for comparison operators.
- Tcl:
- Tcl does not have a separate Boolean type.
- Like in C, integers 0 (false) and 1 (true) are used in Tcl.
- Tcl expressions that evaluate to 1 are considered true.
Introduction and Implementation of BOOLEAN data type in SQL:1999
- SQL:1999 standard introduced BOOLEAN data type as an optional feature.
- Introduced IS (NOT) TRUE, IS (NOT) FALSE, and IS (NOT) UNKNOWN operators.
- SQL BOOLEAN behaves like Booleans in other languages, storing TRUE and FALSE values.
- Nullable BOOLEAN can have the special null value.
- SQL standard defines three literals for BOOLEAN type: TRUE, FALSE, and UNKNOWN.
- Few major SQL systems implement the BOOLEAN feature as of 2012.
- Firebird and PostgreSQL are exceptions, with PostgreSQL using NULL instead of UNKNOWN.
- Microsoft SQL Server does not support BOOLEAN, using BIT data type as a workaround.
- Microsoft Access also uses BIT data type instead of BOOLEAN.
- PostgreSQL has a distinct BOOLEAN type as in the standard.
Treatment of BOOLEAN values in different SQL systems
- Microsoft SQL Server does not support BOOLEAN as a standalone data type.
- Microsoft Access represents TRUE as 1 and does not support the Null tri-state.
- PostgreSQL allows storing predicates directly into a BOOLEAN column.
- MySQL treats BOOLEAN as an alias of TINYINT(1), with non-zero integers considered true.
- Tableau Software has a BOOLEAN data type with True and False literals.
BOOLEAN representation in Forth programming language
- Forth does not have a Boolean type, using regular integers for true and false.
- Value 0 represents false, while -1 represents true in Forth.
- Forth uses one set of logical operators for both mathematical calculations and conditions.
Related topics and references:
- Boolean differential calculus, flag programming, Shannons expansion, three-valued logic, and true/false commands for shell scripting are related topics.
- References include books, programming language documentation, and online tutorials for various languages and SQL systems.