Filter expressions
A filter expression is a JSON object whose keys are table columns and whose values select a filter type. The XYZ API converts it to a SQL condition and passes every value as a query parameter, never as SQL text.[1]
json
{ "retailer": { "in": ["Tesco", "Aldi"] }, "open_date": { "null": false } }| Type | Value | SQL |
|---|---|---|
eq, gt, gte, lt, lte | number or numeric string | "col" = $1, >, >=, <, <= |
in / ni | array, or one value | "col" = ANY ($1) / NOT "col" = ANY ($1) |
like | string; commas separate alternatives | ("col" ILIKE $1 OR …) with a trailing % |
match | string | "col"::text = $1, an exact text match |
boolean | boolean | "col" IS true / IS false |
null | boolean | true: IS NULL; false: IS NOT NULL |
email | any | "col"::text = the requesting user's email |
Combining
- Several columns in one object, and several types for one column, are joined with
AND. - An array of objects is joined with
OR:[{"a": {"eq": 1}}, {"b": {"eq": 2}}]. - A column name must match
^[a-zA-Z_]\w*$. Otherwise the whole object is dropped with a warning. - An unknown type is ignored silently, so a misspelt type filters nothing.
- The numeric types only check that the value is numeric; a value which is not fails the query. The schema accepts numbers and decimal strings. On a text column PostgreSQL compares text, so
{"col": {"gte": 50}}matches'Rooftop'. Use numeric types on numeric columns only.
Where expressions are used
layer.filter.defaultin the workspace, always applied; see layer filter.layer.filter.current, sent by the MAPP library as thefilterrequest param of layer queries.[2]- The
sqlFilterrequest param of query templates without a layer.
Only query templates containing ${filter} apply a filter. A custom query template must include ${filter} for the default and current filters of its layer to apply.
Review notes
- Whether a
filterinsidelayer.rolesis merged intofilter.defaultand applied by queries is not yet confirmed againstgetLayer.jsandcomposeObj.js. - An array value nested under a column (
{"col": [ … ]}) callssqlfilterwithout the request and throws. Use a top-level array forOR.
Examples
A complete workspace with a default filter on the devdb retail points. It shows only Tesco and Aldi stores with a known open date.
json
{
"dbs": "DEVDB",
"locale": {
"layers": {
"retail_points": {
"display": true,
"format": "wkt",
"table": "geodata.uk_glx_open_retail_points",
"geom": "geom_p_4326",
"srid": "4326",
"qID": "id",
"filter": {
"default": {
"retailer": { "in": ["Tesco", "Aldi"] },
"open_date": { "null": false }
}
}
}
}
}
}