This serves 2 purposes:
- Allows functions to be executed once on a specific set of records at a specific time to allow the results to be "saved" in the Query for later use, perhaps in the query itself.
- Allows aggregate functionality to be mixed with standard SQL functionality.
EXECUTE ON ALL | RESULTS | GROUP_BY_RESULTS Expression [ , Expression ]* [ [ AS ] Alias ]
For example:
SELECT * FROM java.io.File WHERE length (name) > @avg_length EXECUTE ON ALL avg (:_allobjs, length) AS avg_length
java.io.File
objects BEFORE processing of the WHERE clause begins. If an "alias" is provided then this is used as the key for the save value in the Query. Thus after the query has been executed the average length of the files would be available by calling:q.getSaveValue ("avg_length");
Also note that the @ save value syntax has been used in the WHERE clause.
The "EXECUTE ON RESULTS" should be used when you wish to execute a number of functions on the objects gained from processing the WHERE clause. For example:
SELECT * FROM java.io.File WHERE length (name) > 20 EXECUTE ON RESULTS avg (:_allobjs, length) AS avg_length
SELECT * FROM java.io.File WHERE length (name) > @avg_length EXECUTE ON RESULTS avg (:_allobjs, length) AS avg_length
null
(however, if the save value is specified by the user prior to execution of the Query then the WHERE clause will limit the set of objects found).The EXECUTE ON GROUP_BY_RESULTS should be used when you wish to execute a number of functions on each of the GROUP BY results. The functions will be executed for each GROUP BY "key". And, as according to the execution scope (see Execution), the :_allobjs special bind variable will contain the objects that were matched in the WHERE clause for the particular group by key.
SELECT * FROM java.io.File GROUP BY parent EXECUTE ON GROUP_BY_RESULTS avg (:_allobjs, length) AS avg_length