Filtering with Predicates
A predicate (or predicate expression) is a logical expression similar to an SQL WHERE clause. By far the most common use of predicates in ibi Patterns - Search is to filter the results of the search. Just as a WHERE clause can be used to limit the output of a SELECT command in SQL, a predicate expression can be used to limit the output of a search in ibi Patterns - Search. Predicate expressions used in this way are called filtering predicates.
An example of a filtering predicate is given in Introduction, where the filtered results are based on the content of a STATE field, using the predicate expression:
$“STATE” = “CA”
Filtering predicates can only modify a search, not constitute it. That is, you cannot execute a search consisting only of a filtering predicate like $“STATE” = “CA”
(to find all records in a table with “CA” as the value of the STATE field). Filtering predicates do not stand alone; they merely modify a search involving the usual simple or cognate query types.
Filtering predicates must be constructed so that the result of their evaluation is either true or false. (This is naturally accomplished through the use of the Boolean operators provided for predicate expressions.) Only records for which the predicate expression evaluates to true are returned by the search.
Filtering predicates are used when there is some specific exact match condition that can be used to eliminate a record from consideration. For example, if you are searching vehicle registrations and looking for a commercial vehicle, you can use a filtering predicate that selects only commercial registrations. If, however, the criteria can not be guaranteed to eliminate a record from consideration, you cannot use a filtering predicate. In the example from Introduction, if there was a significant probability that the STATE field could have an incorrect value, then filtering based on the STATE field would not be valid as you could have some matching records with incorrect STATE values that would be eliminated by the filtering predicate.