Logical and arithmetic expressions
Logical and arithmetic expressions can be used in SHOW clauses and WHERE clauses.
Truth
In WHERE clauses, the following values are considered False:
Boolean False |
Number zero |
Empty string |
Empty list |
None (for example, missing attribute) |
All other values are considered True. This allows simple WHERE clauses that choose only useful values. For example, to find all Software Instance nodes with a populated version:
Expressions
The following logical and arithmetic expressions are supported:
Equality | a = b |
Inequality | a <> b |
Comparison | a > b |
Arithmetic | a + b |
Subwords | a HAS SUBWORD b For a single word search, the condition is true if b is in the list of split words. For a multi-word search:
When used in a WHERE clause, HAS SUBWORD uses the full text indexes maintained by the datastore. It is one of the most efficient ways to find nodes. |
Substrings | a HAS SUBSTRING b |
Regular expression match | a MATCHES b |
Containment | a IN b |
Containment | a IN [b, c, d...] |
Definition | a IS DEFINED |
Inverse | NOT a |
And | a AND b |
Or | a OR b |
Precedence
Operator precedence works as you would expect. Parentheses ( and ) are used to explicitly group operations. Otherwise, in arithmetic expressions, * and / take precedence over + and -. In logical expressions, OR has lowest precedence, followed by AND, followed by NOT, followed by all the other operators. i.e. this expression
is equivalent to
Logical expressions in SHOW clauses
Logical expressions can be used in SHOW clauses. To do so, they must be enclosed in parentheses, e.g.
The behavior of AND and OR in returning one of their input parameters can be useful in handling missing attributes, to avoid output of "None" when an attribute is not available, for example:
OR "Host not identified as virtual")
Logical expression name binding
Logical expressions can be bound to names. For example:
WITH (virtual AND "yes" OR "no") AS is_virtual
SHOW name, @is_virtual
Using a regular expression
The MATCHES condition enables you to search by matching against a regular expression (or regex), a pattern that matches various text strings. For example, A[0-9]+ matches any string that consists of the letter A followed by one or more digits.
Regular expressions have a defined syntax that enables you to define complex matching patterns. BMC Discovery uses the Python implementation; for full syntax and details of use, consult the Python documentation. For more information, see the Python documentation.
The following table lists a few of the matching characters that you can use when constructing regular expressions. An ordinary character, or a sequence of characters, matches that character or string.