Map, filter & aggregate with TRANSFORM()
The TRANSFORM() function allows you to treat arrays of rows like mini tables and manipulate them using familiar FeatureQL syntax.
Here's the general structure:
TRANSFORM(
base
WITH (
WITH [...internal field definitions]
SELECT [...fields to return including group bys]
WHERE [...final filter, equivalent of having]
ORDER BY [...sort expressions]
OFFSET [...skip rows]
LIMIT [...max rows]
)
IMPORTING [...imported features]
) sql
You can:
SELECT ...: generate new fields from existing fieldsWHERE ...: filter post aggregation... FILTER (WHERE ...) GROUP BY ...: aggregate filtered dataORDER BY ...: sort dataLIMIT ...: limit the number of rows returnedOFFSET ...: skip the first n rows
The transformation query must be self contained.
Therefore, you cannot perform the following operations inside the TRANSFORM() query:
- Reference data outside of the array of rows,
- Join with external tables or fields, so no
EXTEND()on fields, - Nest other
TRANSFORM().
You need to perform these operations from the outside of the TRANSFORM() query. See examples here.
Example usage
Here are examples demonstrating practical cases:
On this page