EXISTS(recordset [, KEYED ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )
EXISTS( valuelist )
recordset | The set of records to process. This may be the name of an index, a dataset, or a record set derived from some filter condition, or any expression that results in a derived record set. |
KEYED | Optional. Specifies the activity is part of an index read operation, which allows the optimizer to generate optimal code for the operation. |
valuelist | A comma-delimited list of expressions. This may also be a SET of values. |
UNORDERED | Optional. Specifies the output record order is not significant. |
ORDERED | Specifies the significance of the output record order. |
bool | When False, specifies the output record order is not significant. When True, specifies the default output record order. |
STABLE | Optional. Specifies the input record order is significant. |
UNSTABLE | Optional. Specifies the input record order is not significant. |
PARALLEL | Optional. Try to evaluate this activity in parallel. |
numthreads | Optional. Try to evaluate this activity using numthreads threads. |
ALGORITHM | Optional. Override the algorithm used for this activity. |
name | The algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options. |
Return: | EXISTS returns a single BOOLEAN value. |
The EXISTS function returns true if the number of records in the specified recordset is > 0, or the valuelist is populated. This is most commonly used to detect whether a filter has filtered out all the records.
When checking for an empty recordset, use the EXISTS(recordset) function instead of the expression: COUNT(recordset) > 0. Using EXISTS results in more efficient processing and better performance under those circumstances.
Example:
TrdRec := RECORD
UNSIGNED2 Trd_ID;
INTEGER4 Trd_bal;
INTEGER4 Trd_hc;
END;
PersonRec := RECORD
STRING20 FirstName;
STRING20 LastName;
DATASET(TrdRec) Trd;
END;
Person := DATASET([{'Noah','Brody',[]},
{'Fred','Jones',[{1,2,3},{2,4,5}]},
{'Sue','Smith',[{10,-2,60},{12,14,50}]},
{'Joe','Johnson',[{11,200,3000},{22,140,350},{25,100,850}]},
{'Susan','Stone',[{102,2,30},{125,14,50},{225,14000,50000}]}],PersonRec);
Trades := Person.Trd;
MyBoolean := EXISTS(Trades(Trd_ID = 15));
OUTPUT(MyBoolean); //returns FALSE
TradesExistPersons := Person(EXISTS(Trades));
OUTPUT(TradesExistPersons); //returns 4 records
NoTradesPerson := Person(NOT EXISTS(Trades));
OUTPUT(NoTradesPerson); //returns 1 record
SetExists1 := EXISTS(4,8,16,2,1);
OUTPUT(SetExists1); //returns TRUE
SetVals := [4,8,16,2,1];
SetExists2 := EXISTS(SetVals);
OUTPUT(SetExists2); //returns TRUE
EmptySet := [];
SetExists3 := EXISTS(EmptySet);
OUTPUT(SetExists3); //returns FALSE
See Also: DEDUP, Record Filters