not()
The not() function returns the logical negation (NOT) of a boolean value.
Syntax
not(EXPR)
Parameters
EXPR- The expression to evaluate as a boolean.
Description
The not() function evaluates EXPR. If the result is boolean true, it returns false. If the result is false, it returns true.
If EXPR is null or a non-boolean value such as a number or string, the function returns null.
The return type is always boolean or null.
Error codes
N/A
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Check whether the status code is not 200
table limit=5 WEB_APACHE_SAMPLE | eval result = not(status == 200) | fields status, result -
Filter requests that are neither GET nor POST
table limit=5 WEB_APACHE_SAMPLE | search not(in(method, "GET", "POST")) | # Only request records that are not GET or POST are returned. -
Filter User-Agents that are not crawlers
table limit=5 WEB_APACHE_SAMPLE | eval is_bot = match(agent, "(?i)bot|crawler") | search not(is_bot) | # Only request records that are not crawlers are returned. -
NULL input
json "{'val': null}" | eval result = not(val) | # result: null
Compatibility
The not() function is available since before Sonar 4.0.