BOOLEAN
BOOLEAN in SQL is a data type. It is used to store true/false values. The values it can store are TRUE, FALSE, or NULL.
Example
CREATE TABLE employees ( id SERIAL PRIMARY KEY, name VARCHAR (100), is_manager BOOLEAN);
INSERT INTO employees (name, is_manager)VALUES ('John Doe', TRUE), ('Jane Doe', FALSE);
SELECT * FROM employees WHERE is_manager = TRUE;
Output
id | name | is_manager----+----------+------------ 1 | John Doe | t
Explanation
In the example provided, a table employees
is created with a column is_manager
of BOOLEAN
type. Two rows are then inserted into the table, with ‘John Doe’ having a is_manager
value of TRUE
and ‘Jane Doe’ having an is_manager
value of FALSE
. The SELECT statement retrieves all employees for which the is_manager
field is TRUE
, thus the output includes the record for ‘John Doe’ only.
Example
CREATE TABLE Employee ( emp_id int, is_manager BOOLEAN);
INSERT INTO Employee (emp_id, is_manager)VALUES (1, TRUE), (2, FALSE);
SELECT * FROM Employee;
Output
| emp_id | is_manager ||--------|------------|| 1 | 1 || 2 | 0 |
Explanation
In this case, SQLite does not have built-in BOOLEAN type. However, it uses INTEGER to store Boolean values. SQLite uses 0 for FALSE and 1 for TRUE. The table Employee
created includes a column is_manager
of type BOOLEAN. By inserting the values into Employee
, when fetching the data from the table, it shows 1 for TRUE input and 0 for FALSE input.