7.20.9 Logical predicate
Logical predicates determine the logical value of a value expression.
- Organization of this subsection
(1) Specification format
logical-predicate ::= value-expression IS [NOT] {TRUE|FALSE|UNKNOWN}
(2) Explanation of specification format
- value-expression:
-
Specifies the value expression to be evaluated as a logical predicate. For details about value expressions, see 7.21 Value expression.
The rules are as follows:
-
The data type of the value expression result must be BOOLEAN type.
-
If the result of the value expression is a null value, the logical value of that value expression becomes equivalent to unknown.
-
If a dynamic parameter is specified in the value expression, the data type assumed for the dynamic parameter is BOOLEAN type.
The result of the logical predicate is true when the value specified in the logical predicate (TRUE, FALSE, or UNKNOWN) matches the logical value of the value expression. The following table shows a list of logical predicate results.
Table 7‒16: List of logical predicate results Specified value in logical predicate
Logical value of value expression
True
False
Unknown
IS TRUE
True
False
False
IS FALSE
False
True
False
IS UNKNOWN
False
False
True
- Legend:
-
True: The logical predicate result is true.
False: The logical predicate result is false.
-
- NOT:
-
If NOT is specified, the logical predicate result is true when the value specified in the logical predicate (TRUE, FALSE, or UNKNOWN) does not match the logical value of the value expression. The True and False values in the table above are reversed.
(3) Rules
HADB converts the specified logical predicates are converted to comparison predicates and NULL predicates as shown in the following table and executes them.
|
Specified logical predicates |
Converted predicates |
|---|---|
|
value-expression IS TRUE |
value-expression IS NOT NULL AND value-expression = 'T' |
|
value-expression IS FALSE |
value-expression IS NOT NULL AND value-expression = 'F' |
|
value-expression IS UNKNOWN |
value-expression IS NULL |
|
value-expression IS NOT TRUE |
value-expression IS NULL OR value-expression != 'T' |
|
value-expression IS NOT FALSE |
value-expression IS NULL OR value-expression != 'F' |
|
value-expression IS NOT UNKNOWN |
value-expression IS NOT NULL |
In HADB, logical data in value expressions is treated as CHAR(1) character string data. TRUE is regarded as 'T', and FALSE is regarded as 'F'.
(4) Examples
- Example 1
-
Retrieves employees from the employee table (EMPLIST) who are currently employed and permitted to work remotely.
SELECT "ID","NAME" FROM "EMPLIST" WHERE "IS_ACTIVE" IS TRUE AND "IS_REMOTE_ALLOWED" IS TRUEThe underlined portions show the specification of the logical predicate.
- Example 2
-
Retrieves employees from the employee table (EMPLIST) whose remote work permission has not been set.
SELECT "ID","NAME" FROM "EMPLIST" WHERE "IS_REMOTE_ALLOWED" IS UNKNOWNThe underlined portions show the specification of the logical predicate.